Advertisement
dvdjaco

3.2

Feb 21st, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # #!/usr/bin/python
  2. #
  3. # By dvdjaco
  4. # Exercise 3.2
  5. #
  6. # Exercise 3.2 Rewrite your pay program using try and except so that your program handles
  7. # non-numeric input gracefully by printing a message and exiting the program.
  8.  
  9. prompt_hours = 'Please enter the number of hours: '
  10. prompt_rate = 'Please enter the hourly rate: '
  11.  
  12. try:
  13.     hours = float(raw_input(prompt_hours))
  14.     rate = float(raw_input(prompt_rate))
  15.  
  16.     if hours > 40:
  17.         gross_pay = (40.0 + (hours - 40) * 1.5) * rate
  18.     else:      
  19.         gross_pay = float(hours) * float(rate)
  20.    
  21.    
  22.     print 'The gross pay is ' + str(gross_pay)
  23.  
  24. except:
  25.     print "Please enter numbers for hours and rate."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement