Python Forum
Invalid syntax error, where?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid syntax error, where?
#1
Can anyone help? Wall The question is: "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 pay 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."

I receive the following error:
Error:
SyntaxError: invalid syntax


Here is my code:
try:
    input_hours = input("Enter Hours:")
    hours = float(input_hours)
    input_rate = input("Enter Rate:")
    rate = float(input_rate)
except:
    print("Please enter a numeric input.")
    quit()

def computepay(hours,rate):
    if hours > 40:
        # overtime
        regular = rate * hours
        overtime = (hours - 40.0) * (rate * 0.50)
        total = regular + overtime
    else:
        #regular
        total = hours * rate
    return total

print computepay(hours,rate)
Reply
#2
Parenthesis is missing in print

print(computepay(hours,rate))
Reply
#3
Your print statement should be with parentheses()
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,332 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  Invalid syntax Slome 2 1,970 May-13-2022, 08:31 PM
Last Post: Slome
  print(f"{person}:") SyntaxError: invalid syntax when running it AryaIC 11 16,371 Nov-07-2020, 10:17 AM
Last Post: snippsat
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 2,006 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,011 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,980 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Raise an exception for syntax error sbabu 8 3,171 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,057 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,283 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,445 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020