-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject2Main.py
More file actions
98 lines (82 loc) · 3.13 KB
/
Project2Main.py
File metadata and controls
98 lines (82 loc) · 3.13 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
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
87
88
89
90
91
92
93
94
95
96
97
98
import datetime
from dateutil.relativedelta import relativedelta as rd
def getAge(date):
today = datetime.datetime.today()
try:
date = datetime.datetime.strptime(date, "%Y-%m-%d")
except:
print("Error in the date")
return
age = rd(today, date).years
if age <= 0:
print('Please enter age above 0')
return
approval(age)
def getTestAge(date):
today = datetime.datetime.today()
# date = "05/12/1991"
try:
date = datetime.datetime.strptime(date, "%Y-%m-%d")
except:
print("Error in the date")
return
age = rd(today, date).years
if age <= 0:
print('Please enter age above 0')
return age
def approval(age, rentalList=None):
appDict = {"EC" : 0, "E": 0, "E10": 10, "T": 13, "M": 17, "AO": 18}
#List for movies than can be rented
finalList = []
#List for movies that cannot be rented
failList = []
if rentalList != None:
if age <= 0:
return
else:
print('\n\nAge of renter = ' + str(age))
for rental in rentalList.items():
if age >= appDict[rental[1]]:
finalList.append(rental)
else:
failList.append(rental)
else:
while True:
quitter = input("Enter C to checkout or press R to enter another movie: ")
if quitter.capitalize() == 'C':
break
title = input("Enter the name of the movie: ")
rating = input("Enter the rating of the movie (EC, E, E10, T, M, AO): ")
try:
if age >= appDict[rating.upper()]:
newList = [title, rating]
finalList.append(newList)
else:
newList = [title, rating]
failList.append(newList)
except Exception as e:
print("The rating " + str(e) + " is invalid, please enter a valid rating")
if len(finalList) > 0:
print("\nThe user can rent the following movies: ")
for item in finalList:
print("Title: " + item[0] + "\t\t\tRating: " + item[1])
if len(failList) != 0:
print("\n\nThe user cannot rent the following movies:")
for item in failList:
print("Title: " + item[0] + "\t\t\tRating: " + item[1])
if __name__ == '__main__':
debug = input("Enter Y to test: ")
if debug.capitalize() == "Y":
rentalList = {"Tekken": "M", "Top Gun": "T", "TMNT": "E", "Speed": "AO", "Demolition Man": "E10", "Yea": "EC"}
todaysDate = datetime.datetime.today()
#ageList contains
ageList = [(todaysDate + rd(years=1)), todaysDate, (todaysDate + rd(years=-1)), (todaysDate + rd(years=-16))
, (todaysDate + rd(years=-17)), (todaysDate + rd(years=-18)), (todaysDate + rd(years=-17)),
(todaysDate + rd(years=-18)), (todaysDate + rd(years=-19))]
for year in ageList:
td = str(year.date())
age = getTestAge(td)
approval(age, rentalList)
else:
date = input("Enter your birthday (YYYY-mm-dd): ")
getAge(date)