[Tutor] loop questions

Soliman, Yasmin ysoliman at uncc.edu
Sun Apr 7 00:00:01 CEST 2013


I have two questions on these simple programs:

1st why does this loop keep repeating after I enter 'Quit'?

import calendar
m = raw_input(“Enter a year: “)
while m != “Quit”:
 if calendar.isleap(int(m)):
  print “%d is a leap year” % (int(m))
 else:
  print “%d is not a leap year” % (int(m)) 


2nd  How can I make this program not crash when a user enters a non integer?

m = raw_input(“Enter an integer: “)
while not m.isdigit():
 m = raw_input(“Enter an integer: “)
 num = int(m)


More information about the Tutor mailing list