-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.2-gather_information.py
More file actions
38 lines (27 loc) · 1.39 KB
/
4.2-gather_information.py
File metadata and controls
38 lines (27 loc) · 1.39 KB
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
# 4.2 - Gather Information
SERVICE_CHARGE = 2
TICKET_PRICE = 10
tickets_remaining = 100
### Calculates total price for order ###
def calculate_price(number_of_tickets):
return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE
while tickets_remaining > 0:
print("There are {} tickets remaining.".format(tickets_remaining))
username = input("What is your name? ")
try:
tickets_requested = int(input("How many tickets would you like, {}? ".format(username)))
if tickets_requested > tickets_remaining:
raise ValueError("There are only {} tickets remaining.".format(tickets_remaining))
except ValueError as err:
print("Oh no! That's not a valid value. {} Try again...".format(err))
else:
amount_due = calculate_price(tickets_requested)
print("The total due is ${}".format(amount_due))
complete_purchase = input("Would you like to complete your purchase? y/n: ")
if complete_purchase.lower() == "y":
# TODO: Gather credit card information and process it.
print("Thanks {}, you've completed your order of {} tickets for ${}. Enjoy the show!".format(username, tickets_requested, amount_due))
tickets_remaining -= tickets_requested
else:
print("No problem, {}. Thanks anyways for your interest in the show!".format(username))
print("All of the tickets are sold out.")