Advertisement
namchef

py4inf_ch3

Sep 23rd, 2011
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. ## ex. 3.1 and ex. 3.2
  2.  
  3. ## Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours.
  4. ## Enter Hours: 45
  5. ## Enter Rate: 10
  6. ## Pay: 475.0
  7.  
  8. ## Rewrite your pay program using try and except so that your program handles non-numeric input gracefully by printing a message and exiting the program.         The following
  9. ## The following shows two executions of the program:
  10. ## Enter Hours: 20
  11. ## Enter Rate: nine
  12. ## Error, please enter numeric input
  13. ## Enter Hours: forty
  14. ## Error, please enter numeric input
  15.  
  16.  
  17. hours = raw_input('Enter hours \n')
  18. while hours.isdigit()==False:
  19.     hours = raw_input('Please enter a number for hours \n')
  20. rate = 2.75
  21. hours = float(hours)
  22. if hours <=40:
  23.     pay = hours*rate
  24. else: pay = (40*2.75)+(hours-40)*rate*1.5
  25. print "Pay ", round(pay,2)
  26.  
  27.  
  28. ## ex. 3.3
  29.  
  30. ## Write a program to prompt for a score between 0.0 and 1.0.
  31. ## If the score is out of range print an error.
  32. ## If the score is between 0.0 and 1.0, print a grade using the following table:
  33. ## Score     Grade
  34. ## >= 0.9        A
  35. ## >= 0.8        B
  36. ## >= 0.7        C
  37. ## >= 0.6        D
  38. ## < 0.6      F
  39.  
  40. score = raw_input ('Please give a score \n')
  41. while score.isalpha () == True or float(score)>1.0:
  42.     score = raw_input ('Please input a number between 0.0 and 1.0 for the score \n')
  43.    
  44. score=round(float(score),2)
  45. if score >= 0.9:
  46.     print 'A'
  47. elif score >=0.8:
  48.     print 'B'
  49. elif score >=0.7:
  50.     print 'C'
  51. elif score >=0.6:
  52.     print 'D'
  53. else: print 'F'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement