A problem here


#1

Assign the variable meal the value 44.50 on line 3!

meal = 44.50
restaurant_tip = (15/100)
restaurant_tax = (6.75/100)

print restaurant_tip
print restaurant_tax + tip
total_cost = meal + ((restaurant_tax + tip) * meal)
print total_cost

I just typed this code but it doesn’t shows a perfect value when
restaurant_tip = 15/100
in the command
print restaurant_tip
it shows value = 0
and this affects the entire result
and when I change it to 0.15 it shows correct value everywhere


#2

In Python 2, the / operator performs integer division if both operands are ints. Fractional parts of the result are discarded. That happens here:

restaurant_tip = (15/100)

The result is that 0 is assigned to restaurant_tip.

To prevent the fractional part from becoming discarded, either convert one of the operands to float prior to the division, or use at least one float by including a decimal point in it.

You can do this:

restaurant_tip = (float(15)/100)

or this

restaurant_tip = (15.0/100)

Also, it is best to use the same variable names that are requested in the instructions. If they use tip, for example, you should also use tip. Check all the variable names that are used in the instructions.

tip = (15.0/100)

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.