I'm lost with math operations
up vote
-1
down vote
favorite
I was solving a python task but I didn't get it quite right, I guess. The task is
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. 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 unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Here's my code:
h = input("Hours?")
r = input("Rate?")
h1 = float(h)
r1 = float(r)
def computepay(h1, r1):
p = h1 * r1
return p
if h1 <= 40:
computepay(h1, r1)
else:
g = float(h1 - 40)
g1 = r * 1.5 * g
pay = computepay(h1, r1) + g1
print (pay)
input()
My output is 551.25
Help me, please. I'm completely lost
python-3.x
add a comment |
up vote
-1
down vote
favorite
I was solving a python task but I didn't get it quite right, I guess. The task is
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. 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 unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Here's my code:
h = input("Hours?")
r = input("Rate?")
h1 = float(h)
r1 = float(r)
def computepay(h1, r1):
p = h1 * r1
return p
if h1 <= 40:
computepay(h1, r1)
else:
g = float(h1 - 40)
g1 = r * 1.5 * g
pay = computepay(h1, r1) + g1
print (pay)
input()
My output is 551.25
Help me, please. I'm completely lost
python-3.x
1
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I was solving a python task but I didn't get it quite right, I guess. The task is
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. 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 unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Here's my code:
h = input("Hours?")
r = input("Rate?")
h1 = float(h)
r1 = float(r)
def computepay(h1, r1):
p = h1 * r1
return p
if h1 <= 40:
computepay(h1, r1)
else:
g = float(h1 - 40)
g1 = r * 1.5 * g
pay = computepay(h1, r1) + g1
print (pay)
input()
My output is 551.25
Help me, please. I'm completely lost
python-3.x
I was solving a python task but I didn't get it quite right, I guess. The task is
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. 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 unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Here's my code:
h = input("Hours?")
r = input("Rate?")
h1 = float(h)
r1 = float(r)
def computepay(h1, r1):
p = h1 * r1
return p
if h1 <= 40:
computepay(h1, r1)
else:
g = float(h1 - 40)
g1 = r * 1.5 * g
pay = computepay(h1, r1) + g1
print (pay)
input()
My output is 551.25
Help me, please. I'm completely lost
python-3.x
python-3.x
edited Nov 11 at 14:09
Flimzy
36.6k96496
36.6k96496
asked Nov 11 at 14:07
Styx
4
4
1
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17
add a comment |
1
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17
1
1
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The error is in the part
pay = computepay(h1, r1) + g1
Your are passing the full h1 to the function and not the relevant part 40.0.
pay = computepay(40.0, r1) + g1
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The error is in the part
pay = computepay(h1, r1) + g1
Your are passing the full h1 to the function and not the relevant part 40.0.
pay = computepay(40.0, r1) + g1
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
add a comment |
up vote
1
down vote
The error is in the part
pay = computepay(h1, r1) + g1
Your are passing the full h1 to the function and not the relevant part 40.0.
pay = computepay(40.0, r1) + g1
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
add a comment |
up vote
1
down vote
up vote
1
down vote
The error is in the part
pay = computepay(h1, r1) + g1
Your are passing the full h1 to the function and not the relevant part 40.0.
pay = computepay(40.0, r1) + g1
The error is in the part
pay = computepay(h1, r1) + g1
Your are passing the full h1 to the function and not the relevant part 40.0.
pay = computepay(40.0, r1) + g1
answered Nov 11 at 14:19
Elevator
213
213
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
add a comment |
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249532%2fim-lost-with-math-operations%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why do you "guess" you did not get it right? What output do you get, for which input?
– usr2564301
Nov 11 at 14:17