Advertisement
namchef

py4inf_ch4

Sep 23rd, 2011
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. ## ex. 4.6
  2.  
  3. ## Rewrite  your  pay  computation  with  time-and-a-half  for  overtime  and  create  a function called computepay which takes two parameters (hours and rate).
  4. ## Enter Hours: 45
  5. ## Enter Rate: 10
  6. ## Pay: 475.0
  7.  
  8. def computepay (hours, rate):
  9.     if hours<=40:
  10.         pay=hours*rate
  11.     else:
  12.         pay=(40*rate)+(hours-40)*rate*1.5
  13.     print pay
  14.  
  15. def userinput(a):
  16.     a=raw_input()
  17.     while a.isdigit()==False:
  18.         a=raw_input("Please type a number")
  19.     return a
  20.  
  21. print "Please input the number of hours: "
  22. hours=int(userinput(hours))
  23. print "Please input the rate"
  24. rate=float(userinput(rate))
  25. computepay(hours,rate)
  26.  
  27.  
  28.  
  29. ## ex. 4.7
  30. ##  Rewrite  the  grade  program  from  the  previous  chapter  using  a  function  called computegrade that takes a score as its parameter and returns a grade as a string.
  31.  
  32. ## Write a program to prompt for a score between 0.0 and 1.0.
  33. ## If the score is out of range print an error.
  34. ## If the score is between 0.0 and 1.0, print a grade using the following table:
  35. ## Score     Grade
  36. ## >= 0.9        A
  37. ## >= 0.8        B
  38. ## >= 0.7        C
  39. ## >= 0.6        D
  40. ## < 0.6      F
  41.  
  42.  
  43. score = raw_input ('Please give a score \n')
  44. while score.isalpha () == True or float(score)>1.0:
  45.     score = raw_input ('Please input a number between 0.0 and 1.0 for the score \n')
  46.  
  47. def whatgrade(a):
  48.     round(float(a))
  49.     if a >= 0.9:
  50.         print 'A'
  51.     elif a >=0.8:
  52.         print 'B'
  53.     elif a >=0.7:
  54.         print 'C'
  55.     elif a >=0.6:
  56.         print 'D'
  57.     else: print 'F'
  58.  
  59. whatgrade(score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement