jhylands

prac 2 ex 2

Oct 14th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #!/usr/local/bin/python2.7
  2.  
  3. #function to get the number of hours from the user
  4. def get_time():
  5.   hours = float(raw_input("How many hours did you work this week?"))
  6.   return hours
  7.  
  8. #function to get the wage per hour from the user
  9. def get_wage():
  10.   wage = float(raw_input("How much do you get paid an hour for normal time? (In pounds)"))
  11.   return wage
  12.  
  13. #calculate earnings
  14. def calculate_wage(wage,time):
  15.     if time =< 40:
  16.       standard_earnings = wage * time
  17.     else:
  18.       standard_earnings = 40 * wage
  19.       overtime_earnings =  (time - 40) * wage * 1.5
  20.     return standard_earnings, overtime_earnings
  21.    
  22. #dispay calculated values
  23. def display_earnings(standard_earnings,overtime_earnings, time_worked, wage):
  24.   total_earnings = standard_earnings + overntime_earnings
  25.   print "This week you have earned a total of £", total_earnings#
  26.   if overtime == 0:
  27.     print "This is made up of:"
  28.     print "£" , standard_earnings , " standard earnings at £", wage , " for ", time , " hours"
  29.   else:
  30.     print "This is made up of:"
  31.     print "£" , standard_earnings , " standard earnings at £", wage , " for 40 hours"
  32.     print "and"
  33.     print "£" , overtime_earnings , " overtime earnings at £" , (1.5*wage) , " for ", (time-40) , " hours"
  34.  
  35. #call the function in the progeram
  36. def main():
  37.   time = get_time()
  38.   wage = get_wage()
  39.   standard_earnings, overtime_earnings = calculate_wage(wage,time)
  40.   display_earnings(standard_earnings, overtime_earnings, wage, time)
  41.  
  42.  
  43.  
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment