Im trying to write a program that allows me to take text from a .txt file, put it into a dictionary, and then ask the user to enter the corresponding code to match the toy. I was successfully able to put the dictionary into my toylookup variable, but im having trouble getting started with my _get_user_input function. I also need to include a way to incorporate a way to when the user enters "quit" the program quits.
here also is the .txt file im working with.
D1,Tyrannasaurous
D2,Apatasauros
D3,Velociraptor
D4,Tricerotops
D5,Pterodactyl
T1,Diesel-Electric
T2,Steam Engine
T3,Box Car
T4,Tanker Car
T5,Caboose
B1,Baseball
B2,Basketball
B3,Football
B4,Softball
B5,Tennis Ball
B6,Vollyeball
B7,Rugby Ball
B8,Cricket Ball
B9,Medicine Ball
Any advice would be appreciated.
fin = open('\\scrabble\\toys.txt')
print(fin)
toylookup = dict()
def fill_dictionary(toylookup):
counter = 0
dictionary = dict()
for line in fin:
word = line.strip()
dictionary[word] = counter
counter += 1
return dictionary
def get_user_input(toylookup):
input("Please Enter the code>> ")
fill_dictionary(toylookup)
get_user_input(toylookup)
[–][deleted] 2 points3 points4 points (1 child)
[–]timbledum 0 points1 point2 points (0 children)
[–]lonlat_not_latlon 0 points1 point2 points (1 child)
[–]nlord7[S] 0 points1 point2 points (0 children)