I feel like a while loop is a better choice than using a for loop. But I can't figure out how to integrate the while loop for this situation.
# http://www.dreamincode.net/forums/topic/186908-sanity-check-for-raw-input-being-integer/
# http://learnpythonthehardway.org/book/ex35.html
# http://learnpythonthehardway.org/book/ex48.html
# http://learnpythonthehardway.org/book/ex21.html
# number = (int(raw_input(" Enter a number: ")))
def convert_number(s):
try:
return int(s)
except ValueError:
return None
#exit(5)
#num1 = convert_number('@')
#print "This is what function-except-ValueError returned: %r" % num1
#num2 = convert_number(-3.333)
#print "\nThis is what function returned: %r" % num2
number = raw_input(" Enter a number: ")
num3 = convert_number(number)
print "\n\tThis is what function returned: %r\n" % num3

New Topic/Question
Reply



MultiQuote




|