On 01/05/16 12:55, Olaoluwa Thomas wrote: > It computes total pay based on two inputs, no. of hours and hourly rate.
While you do specify two inputs you immediately throw them away and ask the user to provide the information. In general it is good practice to separate calculation from input/output operations. So in your case write the function to take the values provided by the user and return(not print) the result. Then when you call the function you pass in the values from the user and print the function output. This makes the function more likely to be reusable in other scenarios and easier to debug/test. def computePay(hours, rate): # an exercise for the reader... hours = float(raw_input ('How many hours do you work?\n')) rate = float(raw_input ('What is your hourly rate?\n')) print computPay(hours, rate) > Something seems to be broken. You must learn to provide more specific comments. Define what is broken. Do you get an error message? If so send it (all of it, not just a summary) If no error message what output did you get? What did you expect? Otherwise we wind up just guessing at what is going on. (And only a fool would run allegedly faulty code from an unknown source! :-) > Here's the code: > def computepay(hours, rate): > hours = float(raw_input ('How many hours do you work?\n')) > rate = float(raw_input ('What is your hourly rate?\n')) > if hours > 40: > gross = ((hours - 40) * (rate * 1.5)) + (40 * rate) > elif hours >= 0 and hours <= 40: > gross = hours * rate > print "Your Gross pay is "+str(round(gross, 4)) > > computepay() In this cae I'll guess it's the fact that you tell Python that computePay is a function that takes two arguments (hours, rate) but then call it with no arguments. But you should have got an error message saying something very like that? Here is what I get: >>> def f(x,y): pass ... >>> f() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: f() missing 2 required positional arguments: 'x' and 'y' >>> That's why including the error message helps so much... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor