r/pythonhelp • u/[deleted] • Jul 18 '23
Any ideas as to why its not working?
I have a feeling I'm very close but for some reason just can't get this to run. Any pointers?
Much appreciated.
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input - assume the user types numbers properly.
hrs = float(input("Enter Hours:"))
r = float(input("rate:"))
if hrs <= 40:
regular_gross_pay = hrs * r
print(float(regular_gross_pay))
if hrs > 40:
over_gross_pay = (hrs - 40) * (r * 1.5)
over_gross_pay + regular_gross_pay = over_time_pay
print(float(over_time_pay))
1
3
3
u/sentles Jul 19 '23
In the case that you're over 40 hours, the code in the first if will never run. It will instead jump to the second one. Therefore, you never calculate the regular pay.
Also, you cannot assign values as a + b = c. If you want to add a and b and assign the result to c, the proper way is c = a + b.
2
u/CraigAT Jul 18 '23
Print out the values you calculate.
Have a few test cases (especially edge cases)
You can the use the output to compare to your own manual calculations.
I do see an issue, but doing 1 (and possibly 2) should give you enough info to spot the problem.
2
•
u/AutoModerator Jul 18 '23
Note:
This sub went private for a few days recently in solidarity with other subs who are hoping to get Reddit to reconsider some changes that they have proposed. These changes will affect the Reddit API and many third-party apps that access Reddit. If you are not already aware of the proposed changes, please read up on the topic and the ongoing protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.