-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenreLib.py
38 lines (36 loc) · 1.59 KB
/
GenreLib.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
def genreChooser():
print("Choose the genre of the game (if you want multiple, seperate each by comma):")
genreDict = {1: "Action", 2: "RogueLike", 3: "Adventure", 4: "Role Playing", 5: "Simulation", 6: "Statergy", 7: "Sports", 8: "MMO", 9: "First Person Shooter", 10: "Sandbox"}
for i in genreDict:
print(f"{i}. {genreDict[i]}") #printing The genres and its indecies on the screen
genreLst =[]
while True:
try:
for i in GetGenreNums():
genreLst.append(genreDict[i])
print(genreLst)
break
except KeyError: #if the num entered is out of index of the dictionary
print("Careful, you wanna choose a genre only from the given list. ie, your choices should be from 1-10 not more or less than that: " )
genreLst.clear()
except NameError as DuplicateValueError: #if duplicate values are used.
print(DuplicateValueError.args)
return(genreLst)
def stringToLst(stringNum):
numlst = []
lstStringNum = stringNum.split(",")
for i in lstStringNum:
numlst.append(int(i))
for i in numlst:
if numlst.count(i) > 1: #if a number is repeated twice.
raise NameError("DuplicateValueError")
return numlst
def GetGenreNums():
while True:
try:
numTuple = input()
GenreNums = stringToLst(numTuple)
break
except ValueError:
print("Oops incorrect number entered/wrong delimiter used. Try again!")
return GenreNums