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?

Recommended Answers

All 2 Replies

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.