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.
Brent JohnsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Brent JohnsonAuthor Commented:
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))
    sp = pay-(pay*t)

print("Gross Pay: $ " %gp)
print("Taxes Owed: $ " %sp)
print("Net Pay: $ " %np)
First problem is with the command like print("Gross Pay: $ " %gp). The % here is the operator for a string interpolation. It means that the string before it must contain a placeholder where you want to display the value. To fix it, or you can put the placeholder there or, you can just avoid it by simply using comma in the print command (but this way it would not be formatted). The second problem is that gp is not a single value. It is a tuple with two elements. To put the two together, you can fix the command like:

print("Gross Pay: $%.2f + $%.2f" % gp)

The %0.2f says that you want to place a float value rounded to two decimal places.

It seems you are using Python 3. Then you may prefer the new syntax like

print("Gross Pay: ${:.2f} + ${:.2f}".format(*gp))

It may look more complicated at first in this case.

Another problem is that sp is not calculated in the then branch of the if, nor it is initialized earlier. This way, it is undefined in the later print.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.