It's suppose to be right? What is wrong? Oops, try again. It looks like the printed output is 50.71 instead of 54.63. Double check the instructions!


#1



# Assign the variable total on line 8!

meal = 44.50
tax = 0.0675
tip = 0.15

meal = meal + meal * tax
total = meal + meal*tax


print("%.2f" % total)

Oops, try again. It looks like the printed output is 50.71 instead of 54.63. Double check the instructions!


#2

@1edu,
You forgot to integrate your TIP in the equation......


#3

It didn't ask for that and either way, still didn't work. it gave 50.86 =/= 54.63 (what it wants)


#4

@1edu,
And if you used....

meal = 44.50
tax = 0.0675
tip = 0.15

meal = meal + meal * tax
total = meal + meal*tip


print("%.2f" % total)

#5

Off topic

This exercise has us calculate the tip as a percentage of meal AND tax. That means,

m = 100
t = 6.75 / 100
g = 15 / 100
m1 = m + m * t
m1 = m * ( 1 + t )
m2 = m1 + m1 * g
m2 = m1 * ( 1 + g )
but,
m1 = m * ( 1 + t )
giving,
m2 = m * ( 1 + t ) * ( 1 * g )

So that,

total = meal * (1 + tax) * (1 + tip)

A different perspective that runs counter to the above...

m = 100
x = 6.75 / 100
g = 15 / 100
t = m * 1 + m * x + m * g
t = m * (1 + x + g)

So that,

total = meal * (1 + tax + tip)

Another way of calculating it. This time the tip (gratuity) is calculated against the retail price, tax not included.


#6

Hi Leonhard,

I keep getting message "Oops, try again. It looks like meal is set to 47.50375 instead of 44.50." I have reset the code and even copy and pasted your code given above but i still get the same answer. It seems the the code is not calculating the tip. It looks like meal is set to 47.50375 instead of 44.50. Do you know of any bugs or am I doing some thing stupid?

I hope you can help as I am keen to progress. Thanks.


#7

@pacman00
Depending on which section you are in
The Meal ==> meal = 44.50
The Tax ==> tax = 0.0675
The Tip ==> tip = 0.15
Reassign in a Single line ==> should result in 47.50375
The total ==> 54.63


#8

Hi, I really appreciate you taking the time to reply.
What do you mean reassign in a single line? I have assigned the variable meal the value 44.50 on line 3! Do you think this is an editor issue rather than a code issue. Please forgive any stupid questions that I ask :slight_smile:


#9

@pacman00
I mentioned the =Section= names....
Give us the FULL code you are using
and also specify in which Section you are using the code......


#10

1# Assign the variable meal the value 44.50 on line 3!
2
3 meal = 44.50
4 tax = 0.0675
5 tip = 0.15
6
7 meal = meal + meal * tax
8 total = meal + meal * tip
9
10 print("%.2f" % total)


#11

@pacman00
Remove all the lines from line 4 downward....


#12

Do you mean remove all the empty lines from 4 downward. I tried that, but i am still getting the same error.
Not to worry, I will move on as it's not worth wasting anymore time on it.

I really appreciate your help, thanks.


#13

That worked for me...


#14

A post was split to a new topic: Is that difference even possible in this problem?


#16