0

Why do I get 0True as the answer instead of just True when I type the following code?

x = input ( int()) print ( 2 != "x") >>>0True (if the required input number is 2)

29th Apr 2019, 7:10 PM
anushree sabnis
anushree sabnis - avatar
2 Respuestas
+ 1
It's int(input()), not input(int()). input() will print what is inside the parentheses and int() is 0
29th Apr 2019, 7:30 PM
Anna
Anna - avatar
0
hi anushree sabnis, you get the 0 from the int() method. try this x = input () print(x) print ( 2 != "x") if you want to check the input is an int value, try this user_input = input ("Enter a number") try: val = int(user_input) print("Yes input is an Integer.") print("Input number value is: ", val) if(val != 2): print("User number is <> 2 ") else: print("User number is == 2 ") except ValueError: print("That's not an int!") print("No.. input is not an Integer. It's a string")
29th Apr 2019, 7:22 PM
asa22