What is wrong in the following code?

FOR THE FOLLOWING CODE THE AUTOGRADER IS SHOWING ME-“you should prompt for the data”.
what is wrong in it?

def computepay(a, b):
   a = input("ENTER HOURS WORKED: ")
   b = input("ENTER PAY RATE: ")
   c=float(a)
   d=float(b)
   if c>40:
     g=40*d
     e=(c-40)*d*1.5 +g
     print('Pay',e)
   if c<=40:
     f=c*d
     print('Pay',f)
     
            
y= computepay(45,10.5)

Probably there is an error in your code. You are not using the ‘*’ multiplication operator for multiplying two values,like g=40d should be g=40*d .

1 Like

Thank You for answering, actually the ’ * ’ sign isn’t getting copied so it looks like 40d.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

The autograder wants you to use user-input as the arguments for your function instead of numbers. “45” and “10.5” should not be part of your code. It should be easy to fix.

First: Learn to use names for your variables - if a is “hours”, name it “hours”.
Second: Why are you giving a,b as parameters into the function, if you override them with inputs?
Third: you can typecast an input directly, saving you inbetween variables:
hours = float ( input ( "Enter hours worked: ") )

Finally, your functions has no return value. It just calls print(), which creates an output in the console but returns None.

1 Like

Ohk Understood My mistakes. Thank You so much @Jagaya For identifying the Faults in my Program.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.