Back to questions
JuniorTheoryCommon
What does the program print?
price = 3.14159
qty = 3
print(f"{qty}x{price:.2f}={qty * price:.1f}")3x3.14=9.4
- Expecting
3.1for{price:.2f}, as if2counted all digits:.2fmeans two digits after the decimal point, so3.14159shows as3.14. - Expecting
9.0, as if aninttimes afloatdropped the fraction:qty * priceis about9.425, and.1fkeeps one decimal,9.4.
- Does
{price:.2f}change the value stored inprice? - How would you print a literal
{inside an f-string?