Python Forum
Beginning Payroll code help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginning Payroll code help
#1
Hello to all!
I am a student currently enrolled in a python class at Utica College. This is my first programming language and I am struggling to understand everything and even write the code to the program the teacher wants. We are currently in chapter 3 of Introduction to Programming Using Python, the homework help I need is for 3.9 Payroll.

The instructions are as follows: Write a program that reads the following information and prints a payroll statement.
Employee's name
Number of hours worked in a week
Hourly pay rate
Federal Tax withholding rate
State tax withholding

I have written the following, but need help on figuring out how to find the Gross pay. If I could get some help on what I am missing as I am sure it is very basic and so simple that I am making it very difficult.

# Employee name
employeeName = (input("Enter employee name: "))

# Number of hours worked in a week (e.g. 10)
hoursWorked = (input("Enter hours for one week: "))

# Hourly pay rate (e.g., 14.64)
payRate = (input("Enter pay rate: $ "))

# Federal tax withholding rate (e.g., 20%)
federalTax = (input("Enter federal tax: "))

# State tax withholding rate (e.g., 9%)
stateTax = (input("Enter state tax: "))

# Gross Pay
grossPay = hoursWorked * payRate
(This comes back as a syntax error message)
Reply
#2
Do you provide any input before you get the syntax error? Are you using Python 2 or Python 3?
Reply
#3
Our class is using Python 3. Not I don't provide input before the syntax error as I am trying to find the grossPay I thought the syntax is correct in finding it. I wanted to take hoursWorked * payRate. but this isn't correct
Reply
#4
In both Python versions, I get prompted for your code. Try copying the code on this page into your text editor and see if you still get a syntax error. If so, please post a screenshot, because I'm baffled (unless you're using Python 2 accidentally).
Reply
#5
I ran it in the Python 3.7 that I downloaded, and after I press enter I can enter the name and the rest of the following prompts until the grossPay.
Reply
#6
If you're getting to grossPay then you're providing input, right? Since getting the input blocks the program.

You're trying to multiply strings. You need to tell Python to treat those strings as numbers (either integers or floating point), something like this
grossPay = int(hoursWorked) * int(payRate)
Note that if your payRate (or even hoursWorked) can be non-whole numbers, you'll need to use float instead.
Reply
#7
I will try this! Thank you so much, and yes I was providing the input requested until the error.

After inserting this syntax it doesn't display the answer. See this is where I get stuck and become upset because I don't know how to write the code. It does run without error now, so thank you, I have to come up with federal tax withholding and state tax withholding in the program now.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  beginning python help request (for loop) casey 3 2,706 Oct-26-2018, 07:26 PM
Last Post: casey
  class and objects beginning python 3 pangea 2 3,120 Dec-15-2017, 12:35 PM
Last Post: mpd

Forum Jump:

User Panel Messages

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