-
Notifications
You must be signed in to change notification settings - Fork 0
/
lunchPicker.py
78 lines (61 loc) · 2.14 KB
/
lunchPicker.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
import json
import random
def addOption(options, numOptions, fileName):
newOption = str(input("Enter name of new Lunch option:\n"))
options.append(newOption)
save(options, fileName)
print("\nNew Option Added\n")
listOptions(options)
def removeOption(options, numOptions, fileName):
if numOptions == 0:
print("No options provided, please add some lunch options")
else:
listOptions(options)
indexRM = int(input("\nEnter a number that coresponds to a option you want removed:\n"))
if indexRM >= 1 and indexRM <= numOptions:
options.remove(options[indexRM-1])
save(options, fileName)
print("\nOption removed\n")
else:
print("INVALID INPUT, NUMBER DOES NOT CORRESPOND TO OPTION")
def save(options, fileName):
data = {}
data["Options"] = options
with open(fileName, 'w') as saveFile:
json.dump(data, saveFile)
def pickOption(options, numOptions):
if numOptions == 0:
print("No options provided, please add some lunch options")
else:
print("\nGenerating your lunch destination...\n")
choice = (random.randint(1,numOptions)) - 1
print("Today you will eat at: " + options[choice] + ", Enjoy Your Lunch!")
quit()
def listOptions(options):
print("\nCurrent Options:\n")
for count, option in enumerate(options, start=1):
print(str(count) + ":" + option)
def quit():
exit()
fileName = "options.json"
print("Welcome to the lunch picker!\n\n")
with open(fileName, 'r') as myFile:
options = (json.load(myFile))["Options"]
numOptions = len(options)
print(numOptions)
userInput = ""
while userInput != 'q':
numOptions = len(options)
userInput = str(input(("\nEnter A to add a new lunch option, R to remove a lunch option, L to list all lunch options, P to pick your lunch spot and Q if you would like to quit:\n\n"))).lower()
if userInput == 'q':
quit()
elif userInput == 'a':
addOption(options, numOptions, fileName)
elif userInput == 'r':
removeOption(options, numOptions, fileName)
elif userInput == 'l':
listOptions(options)
elif userInput == 'p':
pickOption(options, numOptions)
else:
print("INVALID INPUT, TRY AGAIN\n")