Calculating a 20% discount

Hi: I’m doing this simple calculation of a 20% discount with three variables, but I can’t find the error:

price = 1.20
discount = price * 20 // 100
total = price - discount
print("%2.2f" % total)

The output in this case is the original price:

1.20 

And in the terminal:

>>> price = 1.20
>>> discount = price * 20 // 100
>>> total = price - discount
>>> print(total)
1.2
>>> print(discount)
0.0

It’s as if discount and total don’t compute anything…it’s must be something obvious that I can’t see.

Thanks!

Isn’t // for floor division? Which means if you get a decimal 0.24 it will return 0. Don’t you need to use /?

2 Likes

Ninja :stuck_out_tongue:

I was so proud to be able to help with a Python question, too

1 Like

And I know nothing about Python, just math. :wink:

2 Likes

Yep, me too… Python is foreign.

1 Like

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