-
Notifications
You must be signed in to change notification settings - Fork 2
/
masterticket.py
44 lines (32 loc) · 1.31 KB
/
masterticket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
TICKET_PRICE = 10
tickets_remaining = 100
# run this code while we have tickets
while tickets_remaining :
# output how many tickets are available
print("There are {} tickets remaining".format(tickets_remaining))
# gather user's name and assign it to a new variable
name = input("Please input your name? ")
print("Welcome, {}".format(name))
# prompt user by name how many tickets they would like to purchase
num_tickets = int(input("How many tickets would you like to purchase {}? ".format(name)))
while num_tickets > tickets_remaining :
print("There are not that many tickets available. Please try again")
num_tickets = int(input("How many tickets would you like to purchase {}? ".format(name)))
# calculate the price
def calculate_price(num_tickets) :
return num_tickets * TICKET_PRICE
# output the price
print("Your total will be ${}".format(calculate_price(num_tickets)))
# prompt user is they want to continue Y/N
confirm = input("Would you like to continue? Y/N ").upper()
# if yes, print out SOLD
if confirm == "Y" :
# decrement tickets remaining
tickets_remaining -= num_tickets
print("SOLD!")
# if no, thank them by name
else :
print("Thank you anyways {}".format(name))
print('\n\n')
# if there are no more tickets, print SOlD OUT
print ("Sold Out!!!")