Advertisement
Mars83

3-1

Oct 3rd, 2011
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #! /usr/bin/env python3.2
  2. # -*- coding: utf-8 -*-
  3.  
  4. # main.py
  5. """ Task: Exercise 3.1
  6.    Rewrite your pay computation to give the employee 1.5 times the hourly rate
  7.    for hours worked above 40 hours.
  8.    Enter Hours: 45
  9.    Enter Rate: 10
  10.    Pay: 475.0
  11.    
  12.    Exercise 2-3:
  13.    hours = input("Enter Hours: ")
  14.    rate = input("Enter Rate: ")
  15.    pay = round(float(hours) * float(rate), 2) # round to 2 digits
  16.                                               # float(x) casts str to float
  17.    print("Pay: " + str(pay))                  # str casts float to string
  18. """
  19.  
  20. # Main
  21. hours = input("Enter Hours: ")
  22. rate = input("Enter Rate: ")
  23.  
  24. if float(hours) <= 40:
  25.     pay = round(float(hours) * float(rate), 2)
  26. else:
  27.     pay = round(40.0 * float(rate)
  28.                 + (float(hours) - 40) * (float(rate) * 1.5), 2)
  29.                 # 40 hours with normal rate, rest with rate * 1.5
  30. print("Pay: " + str(pay))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement