brewersfan1976

ch2-ex1.py

Jul 3rd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. userInput = raw_input("Please enter a hour between 1 and 12:")
  2.  
  3. # error checking to make sure user enters a number
  4.  
  5. if (not userInput.isdigit()):
  6.    print "Please enter a valid number between 1 and 12. Try again"
  7.    quit()
  8.    
  9. hour = int(userInput)
  10.  
  11. # error checking to make sure the user enters a number between 1 and 12
  12.  
  13. if (hour < 1 or hour > 12):
  14.    print "Please enter a valid number betwwen 1 and 12. Try again"
  15.    quit()
  16.  
  17. AM_or_PM = raw_input("Please enter AM or PM: ")
  18.  
  19. # error checking to make sure user enters AM or PM
  20.  
  21. if (AM_or_PM != "AM" and AM_or_PM != "PM"):
  22.    print "Please enter AM or PM. Try again"
  23.    quit()
  24.    
  25. if (hour < 10):
  26.    print "The 12 hour number is", "0" + str(hour)
  27.    
  28. if (hour >= 10):
  29.    print "The 12 hour number is", hour
  30.    
  31. if (AM_or_PM == "AM" and hour < 10):
  32.    print "The 24 hour number is", "0" + str(hour)
  33.    
  34. if (AM_or_PM == "AM" and hour >= 10 and hour != 12):
  35.    print "The 24 hour number is", hour
  36.    
  37. if (AM_or_PM == "AM" and hour == 12):
  38.    print "The 24 hour number is 00"
  39.    
  40. if (AM_or_PM == "PM" and hour == 12):
  41.    print "The 24 hour number is", hour
  42.    
  43. if (AM_or_PM == "PM" and hour < 12):
  44.    print "The 24 hour number is", 12 + hour
Advertisement
Add Comment
Please, Sign In to add comment