0

Why does my code not work?

Hi. I've been learning on SoloLearn for 5 days aprox. and I have tried to program some easy stuff, but I dont know why it does not work like I wish. Could you guys help me please? Here's the code: input("Could you solve a simple equation? If you think you can, press ENTER") input("x+3=10") input("x= ") if input is 7: print("Good job!") print("You have won!") else: print("You missed!") print("You have got another chance.") input("x+3=10") input("x= ") if input is 7: print("Good job!") print("You have won!") else: print("You missed again!") print("You have lost!") I think the mistake is in "if input is 7:" , because wheather you input a 7 or not, the program will say you have missed. Any solutions? Thank you guys!

7th Dec 2017, 3:07 PM
Pau
1 Answer
+ 3
input() returns a value so if you want to use a cobditional statement, you have to assign it to a variable. Moreover, input returs a string - if you want to make a condition on a numerical value, you should convert it to int. You tend to overuse input function. It always expects an input and returns it so maybe there is no point in using this function besides when assign ng to a variable?
7th Dec 2017, 10:14 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar