Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVincenzo Reo
1,373 PointsHow could we get the amount due to print as currency? I tried float(), but it didn't work as I intended.
... num_tickets = int(input("Hi {}! How many tickets would you like to purchase? ".format(name)))
total_cost = num_tickets*TICKET_PRICE
checkout_message = "Awesome sauce {}! Your total amount due is below: ".format(name) amount_due = float(total_cost)
print(checkout_message) print(amount_due)
1 Answer
Jason Larson
8,361 PointsI think this is what you're looking for: This will also add a comma as a thousands separator, if they decide to buy 100 or more tickets. (This is just the last line...)
print("${:,.2f}".format(amount_due))
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsBonus: the
format
method provides rounding!!!Vincenzo Reo
1,373 PointsVincenzo Reo
1,373 PointsThank you Jason Larson and Chris Freeman -- super helpful!!