Home > Net >  Python Print out rounded float plus a string
Python Print out rounded float plus a string

Time:06-18

How do I print out the rounded total of a bill with the tip included at the end of a string?

bill = input('Enter in the bill ($): ')
tip = input('Enter in the tip percentage (%): ')

total_price = float(bill) * int(tip) / 100   float(bill)

print(f"The total cost for dinner is ${total_price}")

I'd like the results to be "The total cost for dinner is $x.xx", where x depends on what numbers were entered.

I'm not sure where to add the round() function in my print statement.

CodePudding user response:

You can simply do

print(f"... ${total_price:.2f}")

or

print(f"... ${round(total_price, 2)}")

Edit: Thanks for pointing out my mistake ddejohn.

CodePudding user response:

I'm not positive but I think the

int(tip) into a float(tip) it should work

  • Related