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










share|improve this question




















  • 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















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










share|improve this question




















  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












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





share|improve this answer





















  • i feel so stupid now, thank you very much!
    – Styx
    Nov 11 at 14:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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





share|improve this answer





















  • i feel so stupid now, thank you very much!
    – Styx
    Nov 11 at 14:33















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





share|improve this answer





















  • i feel so stupid now, thank you very much!
    – Styx
    Nov 11 at 14:33













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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 14:19









Elevator

213




213












  • 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




i feel so stupid now, thank you very much!
– Styx
Nov 11 at 14:33


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python