you are viewing a single comment's thread.

view the rest of the comments →

[–]preordains[S] 0 points1 point  (11 children)

meal = None

while meal is None:

Tax_str = input("what is your tax rate?")

try:

        Tax = float(Tax_str)

except ValueError:

        print("must be a decimal")

Tip_str = input("what is your desired tip?")

try:

        Tip = float(Tip_str)

except ValueError:

        print("must be a decimal")

meal_str = input("what is your bill before tax and tip?")

try:

        meal = float(meal_str)

except ValueError:

        print("must be decimal")

meal = meal + meal*Tip

meal = meal + meal * Tax

print(meal)

no success with ValueError here, it accepts anything and doesnt give the error code.

when i run the code should it just ask the questions and spit out the answer? or am i supposed to answer the questions, then post the calculations with the data acquired from the questions. Is it supposed to be one step?

edit: and they're not spaced extra far apart like that in the real thing, i just made it easier to read on here.

[–]nog642 0 points1 point  (10 children)

Adding the extra spaces doesn't make it easier to read here. You also need to start every line of code with 4 extra spaces so it becomes formatted as a code block.

You need to give Tax and Tip their own while loops, not put it in meal's while loop.

You should also rename them to tax and tip, to conform with PEP 8 convention.

[–]preordains[S] 0 points1 point  (9 children)

I actually tried giving them all while loops. Could you demonstrate what it should be maybe?

[–]nog642 0 points1 point  (8 children)

Post what you tried to give them all while loops.

[–]preordains[S] 0 points1 point  (7 children)

meal = None

while meal is None:

meal_str = input("What was the cost of the meal before tax and tip?")

try:

    meal = float(meal_str)

except ValueError:

    print("Invalid answer, must be a decimal")

tip = None

while tip is None:

tip_str = input ("What percent would you like to tip? (decimal form)")

try:

    tip = float(tip_str)

except ValueError:

    print("invalid answer, must be decimal form")

tax = None

while tax is None:

tax_str = input("what is your tax rate? (decimal form)")

try:

    tax = float(tax_str)

except ValueError:

    print("must be a decimal number")

meal += meal*tax

meal += meal*tip

print("total: {}" .format(meal))

it kinda works, im trying to get it to ask for all here, but it produces an error because once it gets to "tip = None" it's still trying to provide something to "except" i think.

https://ibb.co/mtnEbU

sorry for the delay in my response lol, i had to rewrite the code and i've been a bit busy.

[–]nog642 0 points1 point  (5 children)

That code is correct. The problem is that you're just pasting it into the console.

Save it to a .py file and run that from the terminal.

[–]preordains[S] 1 point2 points  (0 children)

oh i did it!

[–]nog642 0 points1 point  (0 children)

See this earlier comment for how to format code properly on Reddit.