-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parking-Garage.py
86 lines (72 loc) · 3.02 KB
/
Parking-Garage.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class ParkingGarage:
def __init__(self, max_tickets):
self.tickets = list(range(1, max_tickets + 1))
self.parkingSpaces = list(range(1, max_tickets + 1))
self.currentTicket = {}
def takeTicket(self):
if self.tickets:
ticket_number = self.tickets.pop(0)
parking_space = self.parkingSpaces.pop(0)
self.currentTicket[ticket_number] = {
'paid': False,
'parking_space': parking_space
}
print(f"Your ticket is #{ticket_number}")
else:
print("Sorry, the parking garage is full.")
def payForParking(self):
ticket_number = input("What is your ticket #?\n'0' to quit\n")
ticket_number = int(ticket_number)
if ticket_number == 0:
return
if ticket_number in self.currentTicket:
if not self.currentTicket[ticket_number]['paid']:
amount = input("Your ticket # is {} is that correct? Y/N ".format(ticket_number))
if amount.lower() == 'y':
payment_method = input("Your total is $15\nDebit or Credit?\n")
if payment_method.lower() in ['debit', 'credit']:
self.currentTicket[ticket_number]['paid'] = True
print("Thank you for your payment")
else:
print("Invalid payment method.")
else:
print("Payment canceled.")
else:
print("This ticket has already been paid.")
else:
print("Invalid ticket number.")
def leaveGarage(self):
ticket_number = input("What is your ticket #?\n'0' to quit\n")
ticket_number = int(ticket_number)
if ticket_number == 0:
return
if ticket_number in self.currentTicket:
if self.currentTicket[ticket_number]['paid']:
self.parkingSpaces.append(self.currentTicket[ticket_number]['parking_space'])
del self.currentTicket[ticket_number]
else:
print("Please pay for your ticket first.")
else:
print("Invalid ticket number.")
def showSpaces(self):
print("Parking Spaces Left:", len(self.parkingSpaces))
def menu(self):
while True:
print("What would you like to do?\n 'Show Spaces'/'Take Ticket'/'Pay Ticket'/'Leave'/'Quit'")
choice = input().lower()
if choice == 'show spaces':
self.showSpaces()
elif choice == 'take ticket':
self.takeTicket()
elif choice == 'pay ticket':
self.payForParking()
elif choice == 'leave':
self.leaveGarage()
elif choice == 'quit':
break
else:
print("Invalid choice. Please try again.")
if __name__ == "main":
max_tickets = 10
garage = ParkingGarage(max_tickets)
garage.menu()