0
If and Else: basic code problem
I wrote a basic code and i cant seem to get my outputs to work code is: print("Please solve to the following equation: 5+5=") x=input() if x==10: print("Congratulation! that is correct") else: print("Sorry that is incorrect") The problem is that no matter what is inputted the answer is always incorrect, and if I switch it to "if x!=10" the answer is then always correct. I'm not quite understanding where it is i'm going wrong P.S. I'm writing this in Idle
1 Antwort
+ 1
Input in python comes in as a string data type so you have to convert to an int or float data type for this to work. Also, you can put your question in input to avoid that extra line of code.
x=input("Please solve the following equation: 5+5=")
ques = int(x)
if ques==10:
print("Congratulation! that is correct")
else:
print("Sorry that is incorrect")
It can also be wrote like this to condense it more
x=int(input("Please solve the following equation: 5+5=")
)
if x==10:
print("Congratulation! that is correct")
else:
print("Sorry that is incorrect")