
March 27th, 2004, 12:54 AM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Posts: 103
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
|
|
I don't know if this is any faster,but it will loop the raw_input if the input is out of range,or if there's a ValueError(input is a character,not a number).I'm sure there's a better way to do it,but hopefully this will give you some ideas.
Code:
answer = raw_input('Enter a number.Valid range is 1-7:')
while True:
try:
int(answer)
while int(answer) not in range(1, 7):
answer = raw_input('\nInvalid number!Valid range is 1-7:')
break
except ValueError:
answer = raw_input('\nYou must specify a number!Valid range is 1-7:')
if answer == '1':
print 'do response 1'
elif answer == '2':
print 'do response 2'
elif answer == '3':
print 'do response 3'
elif answer == '4':
print 'do response 4'
elif answer == '5':
print 'do response 5'
elif answer == '6':
print 'do response 6'
elif answer == '7':
print 'do response 7'
Code Block Generated With Py2Html
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
|