Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userInput = raw_input("Please enter a hour between 1 and 12:")
- # error checking to make sure user enters a number
- if (not userInput.isdigit()):
- print "Please enter a valid number between 1 and 12. Try again"
- quit()
- hour = int(userInput)
- # error checking to make sure the user enters a number between 1 and 12
- if (hour < 1 or hour > 12):
- print "Please enter a valid number betwwen 1 and 12. Try again"
- quit()
- AM_or_PM = raw_input("Please enter AM or PM: ")
- # error checking to make sure user enters AM or PM
- if (AM_or_PM != "AM" and AM_or_PM != "PM"):
- print "Please enter AM or PM. Try again"
- quit()
- if (hour < 10):
- print "The 12 hour number is", "0" + str(hour)
- if (hour >= 10):
- print "The 12 hour number is", hour
- if (AM_or_PM == "AM" and hour < 10):
- print "The 24 hour number is", "0" + str(hour)
- if (AM_or_PM == "AM" and hour >= 10 and hour != 12):
- print "The 24 hour number is", hour
- if (AM_or_PM == "AM" and hour == 12):
- print "The 24 hour number is 00"
- if (AM_or_PM == "PM" and hour == 12):
- print "The 24 hour number is", hour
- if (AM_or_PM == "PM" and hour < 12):
- print "The 24 hour number is", 12 + hour
Advertisement
Add Comment
Please, Sign In to add comment