Advertisement
Guest User

Untitled

a guest
Jul 9th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. Exercise 3.1 Rewrite your pay computation to give the employee 1.5 times the hourly rate for
  2. hours worked above 40 hours
  3. a="Enter Hours:"
  4. b=raw_input(a)
  5. c="Enter Rate:"
  6. d=raw_input(c)
  7. if int(b)>40:
  8.    
  9.     print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
  10. else:
  11.    
  12.     print "Pay2",int(b)*float(d)
  13.  
  14. Exercise 3.2 Rewrite your pay program using try and except so that your program handles
  15. non-numeric input gracefully by printing a message and exiting the program. The following
  16. shows two executions of the program:
  17.  
  18. a="Enter Hours:"
  19. try:
  20.     b=raw_input(a)
  21.     int(b)
  22. except:
  23.     print "Error, please enter a numeric input"
  24. c="Enter Rate:"
  25. try:
  26.     d=raw_input(c)
  27.     float(d)
  28.     if int(b)>40:
  29.             print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
  30.     else:
  31.             print "Pay2",int(b)*float(d)
  32. except:
  33.     print "Error,please enter a numeric input"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement