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

3rd Jan 2017, 11:12 AM
Kushal Bhagat
Kushal Bhagat - avatar
3 Respostas
+ 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"))
3rd Jan 2017, 11:36 AM
Ethan
Ethan - avatar
+ 1
Yes, it works!!! Thanks a lot Eitan Stein!
3rd Jan 2017, 1:04 PM
Kushal Bhagat
Kushal Bhagat - avatar
+ 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)
20th Feb 2017, 6:14 PM
Abdelkader Ait Assou
Abdelkader Ait Assou - avatar