0

What do I need to do to make rules for user input? Say I want the user to choose a number 1-5. If they pick one, I want to go to the next step. If they don't I want to tell them that they have to pick a number between 1-5 to continue. Code?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by snippsat
0

Some hint
You will not get finish code or so much help if you dont show some effort.

>>> a = 3
>>> if a <=5 and a >= 1:
...     print 'Number are between 1 and 5'
...     
Number are between 1 and 5
>>> a = 7
>>> if a <=5 and a >= 1:
...     print 'Number are between 1 and 5'


>>> b = int(raw_input('Enter a number: '))
Enter a number: a

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    b = int(raw_input('Enter a number: '))
ValueError: invalid literal for int() with base 10: 'a'

>>> try:
	b = int(raw_input('Enter a number: '))
except ValueError:
	print 'Please number only'

	
Enter a number: a
Please number only

Edited by snippsat: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.