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 trialArnold Ganga
1,698 PointsMY SOLUTION
TICKET_PRICE = 10
tickets_remaining = 100
Output the number of tickets remaining using the tickets remaining variable
print("The number of tickets remaining is {}".format(tickets_remaining))
Gather the user 's name and assign it to a new variable
user_name = input("May you please enter your name: ")
Prompt the user by name and ask them how many tickets they would like
num_of_tickets = int(input("{} How many tickets would you like to order : ".format(user_name.capitalize())))
Calculate the price (number of tickets multiplied by the price) and assign it to a variable total
total_cost = num_of_tickets*TICKET_PRICE
Output the price to the screen
print("{}, the total cost of the tickets you would like to order is ${}".format(user_name,total_cost))
2 Answers
Ams BM
5,898 PointsNice, mines is quite similar but I like using the f string
method, rather than the .format
method
TICKET_PRICE = 10
ticket_remaining = 100
print(f"There's {ticket_remaining} tickets remaining.")
users_name = input("Please enter your name: ")
num_of_tickets = int(input(f"Hi {users_name}, how many tickets would you like? "))
ticket_price_cal = num_of_tickets * TICKET_PRICE
print(f"That's {num_of_tickets} tickets, total cost is ${ticket_price_cal}")
Raj Maraj
Data Analysis Techdegree Student 4,791 PointsOh yea I really like the f string
method rather than .format
, It easier for me to correlate what info is going where.
TICKET_PRICE = 10
tickets_remaining = 100
#Output how many tickets are remaining using the tickets_remaining variable
print("There are {} tickets remaining.".format(tickets_remaining))
#Gather the user's name and assign it to a new variable
user_name = input("What is your name? ")
#Prompt the user by name and ask how many tickets they would like
quantity_of_tickets = input("{}, How many tickets would you like? ".format(user_name))
quantity_of_tickets = int(quantity_of_tickets)
#Calculate the price (number of tickets x price) and assign it to a variable
cost = quantity_of_tickets * TICKET_PRICE
#Output the price to the screen
print("The total is ${}".format(cost))
#Output the price using f string
print(f"The total is ${cost}")