This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by 16mcclearya
about 10 years

Why does this code work for 5/5?

After much frustration stemming from the code it says to use (total = meal + meal * tip) not working, I tried my own code;

total = meal + meal * tip + meal * tax

That didn’t work either, so I decided to try adding the difference of my result and the actual result. Since I didn’t remember the numbers, after adding in the “+” after tax, I hit “Save and Submit code” to see the numbers… and it passed me. Full code below:

meal = 44.50 tax = 0.0675 tip = 0.15

total = meal + meal * tax +

print(“%.2f” % total)

Answer 53172d3b282ae3f1390023e2

0 votes

Permalink

I don’t have an answer for why it works, I just wanted to say thank you for sharing because I got stuck the exact same place, all my code was correct and just as they were asking for but it wouldn’t pass and I did what you did and it worked. This site is a bit buggy some times it seems. Thank you!

points
Submitted by Kathy Gleason
about 10 years

1 comments

16mcclearya about 10 years

No problem. Same error, said my math didn’t add up, and I remembered one lesson in HTML where the way someone passed was to delete the code between the tags. So, as I said, I threw in my own stuff, and it eventually worked.

Answer 531824d3631fe9e4c1002ac2

0 votes

Permalink

Yep, same here… Threw me around, looked on the site after half an hour and then found this, it works.

points
Submitted by Wate006
about 10 years

Answer 5318ad809c4e9dc4930006b7

0 votes

Permalink

This worked just fine:

# Assign the variable meal the value 44.50 on line 3!

meal = 44.50 tax = 0.0675 tip = 0.15

total = ((meal * tax) * tip)

print (total)

points
Submitted by Benjamin Sturm
about 10 years

Answer 534703957c82ca5c340001b9

0 votes

Permalink

Though the code gave me error but it also passed.It looks like site has some issues

Assign the variable total on line 8!

meal = 44.50 tax = 0.0675 tip = 0.15

total = meal + meal*tax +

print(“%.2f” % total)

File “python”, line 8 total = meal + meal*tax + ^ SyntaxError: invalid syntax

points
Submitted by alohia123
about 10 years

Answer 534704709c4e9df65f0001c5

0 votes

Permalink

The code will not work since it throws invalid syntax but I am still not sure how codecademy site said my code passed.the page has bug in it

points
Submitted by alohia123
about 10 years

Answer 545597ca631fe9d8e300383d

0 votes

Permalink

I tried that method but it would not work. So I just hacked around thoughtlessly. Then I hit total = meal + meal*tip, and took ‘’tax” out of the line. So if I figure correctly, it worked because (meal * tax) had already been used and was now stored in the value “meal”. So I just added + tip and luckily it worked.. because I CANNOT do math at all and any extra math work would have eluded me.

points
Submitted by ayn randy
over 9 years

Answer 554d6a89d3292f53c3000314

0 votes

Permalink

I had to change the price of the meal to make the code add up to the value it wanted

meal = 51.18 tax = 0.0675 tip = 0.15

total = meal + meal * tax

print(“%.2f” % total)

points
Submitted by Billistic
almost 9 years