I want to get an exception in the anyvalue variable if i put a value like float (with any value too, but neihter text or int), but it doesn’t work
it only works in the following variables, if i put any text in the anyvalue (on which i want to work, the first variable of the script), it does a thing, and the same with number, but if i put a float value(for example) it doesn’t give me the exception and takes it as if it were a int
import time
try:
anyvalue = input(“Introduce texto o numero>_ “) #this is the variable i want to get the error
if anyvalue.isdigit():
int(anyvalue)
print(“Haz elegido numeros”)
time.sleep(1.5)
num1 = int(input("nAhora escribe un numero entero: "))
num2 = int(input("Ahora escribe otro numero entero: "))
time.sleep(2)
action = input("""n¿Qué harás con los numeros?
Sumar
Dividir
Multiplicar
Restar
_ “””).lower()
if action == "sumar":
print(num1 + num2)
elif action == "dividir":
print(round(num1 / num2))
elif action == "multiplicar":
print(num1 * num2)
else:
print(num1 - num2)
print("Terminando...n")
time.sleep(3)
else:
name = input("Ya que elegiste texto, pon un nombre>_ ")
time.sleep(2)
age = input("¿Cuantos años tienes?>_ ")
cya = print(f"Nos vemos {name}")
except ZeroDivisionError:
print(“Error: No se puede ni dividir entre 0”)
except ValueError:
print(“Error: Introduce solo numeros enteros o texto”)
else:
print(“Salio todo bien”)
finally:
print(“Saliendo…”)
time.sleep(3)
I tried to make the anyvalue variable
karen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.