0
I want to build a simple program. Please tell me if it is correct b coz i am not getting the results.......
x=input("Enter a number between 1 to 3") if x==1: print("You typed number one") elif x==2: print("You typed number two") else: print("You typed number three") This is the code. I wan the input to compare with the if condition and just print the result. Please tell me where I am wrong
3 odpowiedzi
+ 1
the input from the user is a string - u need to convert it into an integer to work
try
x=int(input("Enter a number between 1 to 3"))
+ 1
Yes, it works!!! Thanks a lot Eitan Stein!
+ 1
Here is my code:
x = -1 # -1 to be sure that you enter the while block code cause it is not in the range of 1 and 3.
successful = (x in range(1, 4))
while successful == False:
x = input("Please enter a number between 1 and 3: ")
successful = (x in range(1, 4))
print "You typed: %s" %(x)