Link to home
Start Free TrialLog in
Avatar of Brent Johnson
Brent JohnsonFlag for United States of America

asked on

Need help with developing flow chart then coding in python this simple problem?

Hello Experts,

Can anyone help me out with this problem?  I need to develop a flow chart and then write a python program for the following problem:

"Input an ID Number, Rate of Pay, Hours Worked, and the Tax Rate.  Calculate Gross Pay, Taxes owed, and the Net Pay.  (Remember to pay Time and a Half for Over-Time Pay).  Print out the Gross Pay, Taxes Owed, and the Net Pay."

Any help would be greatly appreciated.
Avatar of pepr
pepr

To develop a flow chart, write the steps on the paper from top down and put them to the boxes joined by arrows.

When calculating some of the values, you find them non-linear. This means that there is for example special case when part of the worked hours is paid differently, This way you have to test whether the hours are bigger than normal working hours. Think in terms: "If hours is greater than normal working hours, then calculate how much extra work was done and use a coeficient to calculate the salary for the over-time".

Each "If" means a decision. It is drawn as a diamond shape in the flow chart splitting the flow "this way or that way". In a programming language, it will become an "if" construct.

Don't sit at the computer first. Take a sheet of paper, pencil, and your brain. Do not think about all details at once. Draw a first rough solution that is clear and understandable to you. Then refine each box of the flowchart thinking separately about that part of the solution (each of the boxes will be expanded to its separate flow chart -- this is called top-down decomposition [in the sense deeper, more details]-- just that simple). Finally, the boxes of the flow chart will be that simple that you can directly write them as the source code in Python.
Avatar of Brent Johnson

ASKER

Okay, I have the flow chart done, and I'm trying to do the code, but here is what I have and it doesn't work.  What is wrong?

ID = input("What is your ID number? ")
hours = float(input("How many hours did you work? "))
wage = float(input("What is your hourly wage? $"))
tax = float(input("What is the tax rate? %"))

t = tax/100
pay = hours*wage
np = pay - (pay * t)
gp = 40*wage, (((hours-40)*(1.5*wage))*(t))

if hours > 40:
    print("Gross Pay: $ " %gp)
    #gp = 40*wage, (((hours-40)*(1.5*wage))*(t))
else:
    sp = pay-(pay*t)



print("Gross Pay: $ " %gp)
print("Taxes Owed: $ " %sp)
print("Net Pay: $ " %np)
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial