-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLUNCH-PROTOTYPE.py
363 lines (272 loc) · 9.92 KB
/
LUNCH-PROTOTYPE.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import sys
import random
from random import shuffle
import time
def edit_distance(s1, s2):
s1=s1.lower()
s2=s2.lower()
m=len(s1)+1
n=len(s2)+1
tbl = {}
for i in range(m): tbl[i,0]=i
for j in range(n): tbl[0,j]=j
for i in range(1, m):
for j in range(1, n):
cost = 0 if s1[i-1] == s2[j-1] else 1
tbl[i,j] = min(tbl[i, j-1]+1, tbl[i-1, j]+1, tbl[i-1, j-1]+cost)
return tbl[i,j]
restaurants = []
with open("LUNCH_restaurants_list.txt","r") as f:
for line in f:
line = line.rstrip()
restaurants += [line]
longest_string = 100
destination = ""
rest_len = len(restaurants)
num_rest = int(input("How many restaraunts to start with? "))
reduced_rest_list = []
shuffle(restaurants)
while len(reduced_rest_list) < num_rest:
randint = random.randint(0, rest_len-1)
rest = restaurants[randint]
if rest not in reduced_rest_list:
reduced_rest_list.append(rest)
# Sort list by name (case-insensitive)
reduced_rest_list.sort(key = lambda x: x.lower())
print("############## PHASE 1 ##############\n")
print(reduced_rest_list)
print()
while len(reduced_rest_list) > 6:
inpt = input("Choose a restaurant to remove from the list: ")
thedevilhimself = str(inpt)
toRemove=""
minEdit=100
for i in reduced_rest_list:
tmp = edit_distance(thedevilhimself.lower(), i.lower())
if (tmp<minEdit): minEdit=tmp; toRemove=i
try:
print("Removing {}".format(toRemove))
reduced_rest_list.remove(toRemove)
except ValueError or NameError:
print("\nThis is not a restaurant in the list...")
print("You probably spelled it wrong genius.")
print("Choose one that is actually in the list.")
time.sleep(3)
print("\n")
reduced_rest_list.sort(key = lambda x: x.lower())
print(reduced_rest_list)
print("\n")
print()
print("############## PHASE 2 ##############\n")
print("These are the 6 restaurants you have chosen for today:\n1. {}\n2. {}\n3. {}\n4. {}\n5. {}\n6. {}\n".format(reduced_rest_list[0], reduced_rest_list[1], reduced_rest_list[2], reduced_rest_list[3], reduced_rest_list[4], reduced_rest_list[5]))
choice = input("Make a choice:\n" + "(1) Roll a die\n" + "(2) Vote\n")
print("\033[A" + " "*longest_string + "\033[A")
while not isinstance(choice, int) or (choice != 1 and choice != 2):
#print("Please input either 1 or 2.")
#choice = input("Make a choice:\n" + "(1) Roll a die\n" + "(2) Vote\n")
#while not isinstance(choice, int):
try:
choice = int(choice)
if choice != 1 and choice != 2:
raise ValueError
except ValueError:
print("\nPlease input either 1 or 2.")
choice = input("Make a choice:\n" + "(1) Roll a die\n" + "(2) Vote\n")
print("\033[A" + " "*longest_string + "\033[A")
print()
if choice == 1:
#print("Time to roll a die and pick one! Hit enter to roll!")
#input()
for i in range(random.randint(1,6)):
print("Rolling" + "." * i, end="\r")
time.sleep(1)
num = random.randint(1, 6)
print("\nYou rolled a {}!".format(num))
destination = reduced_rest_list[num-1]
elif choice == 2:
finalists = {}
reduced_rest_list.sort()
for i in range(len(reduced_rest_list)):
finalists[reduced_rest_list[i]] = 0
print("Final list:\n")
for i in range(len(reduced_rest_list)):
print("%g. " % (i+1) + reduced_rest_list[i])
print()
num_voters = input("Enter number of people who are voting: ")
print("\033[A" + " "*longest_string + "\033[A")
while not isinstance(num_voters, int):
try:
num_voters = int(round(float(num_voters)))
if num_voters < 1: raise ValueError
except ValueError:
print("Not a valid input.")
num_voters = input("Enter number of people who are voting: ")
print("\033[A" + " "*longest_string + "\033[A")
if num_voters > 1:
print("There are %g people voting\n" % num_voters)
else:
print("There is %g person voting\n" % num_voters)
for voter in range(num_voters):
print("Voter number %g, please enter the indices of your top 3 choices in order." % (voter+1))
vote1, vote2, vote3 = 0, 0, 0
# First choice is given 3 points
vote1 = input("First choice (3 points): ")
print("\033[A" + " "*longest_string + "\033[A")
# Preventing human errors in input
while not isinstance(vote1,int):
try:
vote1 = int(round(float(vote1)))
finalists[reduced_rest_list[vote1-1]] += 3
except ValueError:
print("Not a valid input.")
vote1 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
except (IndexError, KeyError) as e:
print("Your choice is not in the final list.")
vote1 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
# Second choice is given 2 points
vote2 = input("Second choice (2 points): ")
print("\033[A" + " "*longest_string + "\033[A")
# Prevents one choice from getting stacked
while True:
try:
vote2 = int(round(float(vote2)))
while vote1 == vote2:
vote2 = input("You can't pick the same restaurant more than once. Please pick a different one: ")
print("\033[A" + " "*longest_string + "\033[A")
vote2 = int(round(float(vote2)))
finalists[reduced_rest_list[vote2-1]] += 2
break
except ValueError:
print("Not a valid input.")
vote2 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
except (IndexError, KeyError) as e:
print("Your choice is not in the final list.")
vote2 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
# Third choice is given 1 point
vote3 = input("Third choice (1 point): ")
print("\033[A" + " "*longest_string + "\033[A")
while vote1 == vote3 or vote2 == vote3:
vote3 = input("You can't pick the same restaurant more than once. Please pick a different one: ")
print("\033[A" + " "*longest_string + "\033[A")
while True:
try:
vote3 = int(round(float(vote3)))
while vote1 == vote3 or vote2 == vote3:
vote3 = input("You can't pick the same restaurant more than once. Please pick a different one: ")
print("\033[A" + " "*longest_string + "\033[A")
vote3 = int(round(float(vote3)))
finalists[reduced_rest_list[vote3-1]] += 1
break
except ValueError:
print("Not a valid input.")
vote3 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
except (IndexError, KeyError) as e:
print("Your choice is not in the final list.")
vote3 = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
print("Voter number %g is done.\n" % (voter+1))
time.sleep(2)
results = sorted(finalists, key=finalists.get, reverse=True)
print("The votes are in!")
for rest in results:
print( rest + ": " + str(finalists[rest]) + " points" )
tie = 1
for i in range(1,len(results)):
if finalists[results[0]] == finalists[results[i]]:
tie += 1
elif tie > 1:
del results[i:]
break
while tie > 1:
time.sleep(2)
print("But we're not done yet!")
time.sleep(2)
print()
if tie == 2:
print("We have a tie between " + results[0] + " and " + results[1] + ".")
elif tie > 2:
tie_announce = "We have a " + str(tie) + "-way tie between "
for i in range(tie):
if i == tie-2:
tie_announce += results[i] + ", and " + results[i+1] + "."
break
tie_announce += results[i] + ", "
print(tie_announce)
tiebreak = {1:"Roll a die!", 2:"Vote again!"}
print("The final decision! What will it be?")
for i in range(len(tiebreak)):
print("(" + str(i+1) + ") " + tiebreak[i+1])
tiebreaker = input()
print("\033[A" + " "*longest_string + "\033[A")
while not isinstance(tiebreaker, int):
try:
tiebreaker = int(round(float(tiebreaker)))
print("You have chosen to " + tiebreak[tiebreaker].lower())
except ValueError:
print("Not a valid input.")
tiebreaker = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
except KeyError:
print("Your choice is not valid.")
tiebreaker = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
time.sleep(2)
if tiebreaker == 1:
for i in range(random.randint(1,6)):
print("Rolling" + "." * i, end="\r")
time.sleep(1)
num = random.randint(1, tie)
print("\nYou rolled a {}!".format(num))
destination = results[num-1]
break
elif tiebreaker == 2:
final = { results[i-1]:0 for i in range(1,len(results)+1) }
print()
print("Here is the list choices:")
for i in range(len(results)):
print("(" + str(i+1) + ") " + results[i])
time.sleep(2)
print("Only 1 vote per person. Choose wisely.")
time.sleep(2)
for voter in range(num_voters):
vote = input("Voter number %g, please enter your vote: " % (voter+1))
print("\033[A" + " "*longest_string + "\033[A")
while not isinstance(vote,int):
try:
vote = int(round(float(vote)))
final[results[vote-1]] += 1
except ValueError:
print("Not a valid input.")
vote = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
except (IndexError, KeyError) as e:
print("Your choice is not valid.")
vote = input("Please enter a valid choice: ")
print("\033[A" + " "*longest_string + "\033[A")
print("Voter number %g is done." % (voter+1))
time.sleep(2)
results = sorted(final, key=final.get, reverse=True)
print("The final votes have been casted!")
time.sleep(2)
print("Here is the result:")
for rest in results:
print(rest + ": " + str(final[rest]) + " points" )
destination = results[0]
tie = 1
for i in range(1,len(results)):
if final[results[0]] == final[results[i]]:
tie += 1
elif tie > 1:
del results[i:]
break
else:
destination = results[0]
time.sleep(3)
print()
print("Today's lunch will be at {}.".format(destination))
print("Enjoy! :)")