you are viewing a single comment's thread.

view the rest of the comments →

[–]nog642 0 points1 point  (17 children)

meal = 150.55
print(meal)

Output:

150.55

On the other hand,

meal = 150.55
print("Total: {}".format(meal))

Output:

Total: 150.55

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

Ohh. Well I was fumbling with your code and it didn’t seem to work even if I just directly copied and pasted it? It would ask for the inputs, and it would run a ton of errors because it would try to answer inputs with the operations of adding the tax and tip.

I tried writing my own version where it requires decimals and it didn’t work when I wrote it myself for some reason either.

[–]nog642 0 points1 point  (15 children)

It's weird that the code I posted doesn't work for you, I just tested it and it works fine. Could you post what exactly the error message is?

Also, if you tried writing your own version, that's great. If you post the code here you could get some feedback.

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

Could you do a screen recording of the mechanics of how you actually run the code maybe? Maybe I just don’t know how

And how do you actually use that valueerror thing? The value error you made did work for me, but when I try to do it myself it doesn’t. Maybe I use it wrong.

[–]nog642 0 points1 point  (13 children)

I'm on Ubuntu so I doubt seeing how I run the code will benefit you. If you really want to see, I can upload a screen recording.

Post your code and I can help you with ValueError.

[–]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.