+ 1

How do you use inputs and if variables?

whenever I put something like "if (x) == 2" I always get an error, can anyone explain? My code is: Stuff = [(x),(y),(z)] x = input("Enter a number:\n") y = input("Enter another:\n") z = input("Enter one more please:\n") if (x) = 3 print ("Nice")

30th Jun 2016, 8:31 PM
Jack
4 Answers
+ 1
I see additional mistakes to the one corrected by the other users. Remove the circle brackets. You are unintentionally making tuples. You tried to make a list with undefined variables. input() should be int(input ()) in order to convert the received value to an integer and compare it to another integer. Or you could compare x to "3" instead if you will not use x for arithmetic. Your code should be: x = int (input ("Enter a number \n")) y = int (input ("Enter another \n")) z = int (input ("Enter one more please\n")) if x == 3: print ("Nice")
2nd Jul 2016, 11:03 PM
Gershon Fosu
Gershon Fosu - avatar
0
it should be if x = 3: print ("nice")
30th Jun 2016, 8:50 PM
Pablo
Pablo - avatar
0
it should be if x == 3: print("nice")
1st Jul 2016, 12:38 PM
Abuzer
0
A single equal to " = " is an a assignment operator, and does compare left hand side with right hand side, instead it assigns 3 to x. If you want to compare lhs and rhs, always use the comparison operator ==
1st Jul 2016, 5:02 PM
Aditya Deshpande
Aditya Deshpande - avatar