csev / py4e

Web site for www.py4e.com and source to the Python 3.0 textbook

Home Page:http://www.py4e.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conditional Execution - Exercise 1 typo

darykm opened this issue · comments

Hello Chuck,

I just finished exercise 1 and was checking the math and I believe there is a typo.

Exercise 1: Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours.

Enter Hours: 45
Enter Rate: 10
Pay: 475.0 <------ This should equal $525 dollars if employee is getting paid $15 dollars an hour for the time worked after 40 hours.

my code:

hours = float(input('How many hours?'))
rate = float(input('What is your hourly rate?'))
regpay = hours * rate
if hours > 40.0:
othours = hours - 40.0
otrate = rate * 1.5
otpay = othours * otrate
pay = regpay + otpay
print(pay)

The math is not wrong. You made a very small error in your code.

Fixed my code! Thank you so much!

hours = float(input('How many hours?'))
rate = float(input('What is your hourly rate?'))
regpay = 40.0 * rate <------- Original code was double counting the 5 additional hours here
if hours > 40.0:
othours = hours - 40.0
otrate = rate * 1.5
otpay = othours * otrate
pay = regpay + otpay
print(pay)