Python Python Basics All Together Now Branch and Loop

waiting for answers yes or not to buying tickets

TICKET_PRICE = 10

tickets_remaining = 100

Output how many tickets are remaining using the tickets_remanning variable

print("There are {} tickets remainimg.".format(tickets_remaining))

Gather the users name and assign it to the new variable

name = input("What's is your name? ")

prompt the user by name and ask how many tickets they would like

num_tickets = input("How many tickets would you like to buy {}? ".format(name)) num_tickets = int(num_tickets)

Calculate the price (number of tickets multiplied by the price) and assign it to a variable

amount_due = num_tickets * TICKET_PRICE

Output the price to the screen

print("The total due is ${}".format(amount_due))

prompt user if they want to proceed. Y/N?

name = input("Would you like to buy the tickets {}? ".format(name)) if name <----STUCK HERE

If they want to proceed

#print out to the screen "SOLD!" to confirm purchase

#and then decrement the ticket remaining by the number of tickets purchased

otherwise ....

#Thank them by name

Steven Parker
Steven Parker
176,604 Points

Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:
Or watch this video on code formatting.

2 Answers

Steven Parker
Steven Parker
176,604 Points

Here's a few hints:

  • use a different variable to store the answer so you can save "name" for the "thank you" message
  • test the answer in an "if" statement by comparing it with "Y"
  • print the "sold" message only if the test succeeds

Thank you