1
a = int (input ("insira um número :"))
if a != int :
print ("isto não é um numero inteiro")
else :
print ("seu número foi :"+ str(a))
I’m trying to make a program where the user puts a value and the program says what was the value that he entered, but if I inserted a letter, from this error screen.
It turns out that when he inserts a number the program does not recognize as such.
This answers your question? How to use the if block with Python variable types?
– JeanExtreme002
pass the variable in type() to be able to condition with its type: type(var) != int
– Elton Nunes
It makes no sense to test the function return type
int()because that function ALWAYS returns an object of typeint! What you want is to capture the exception that occurs when the functionint()tries to convert an invalid text; see the answer below– nosklo