Problem I was trying to assign user input as a key in a dictionary. If user input is a key then print out its value, else print invalid key. The problem is the keys and the values will be from a text file. For simplicity I will just use random data for the text. Any help would be appreciated.
file.txt
Dog,bark
Cat,meow
bird,chirp
Code
def main():
file = open("file.txt")
for i in file:
i = i.strip()
animal, sound = i.split(",")
dict = {animal : sound}
keyinput = input("Enter animal to know what it sounds like: ")
if keyinput in dict:
print("The ",keyinput,sound,"s")
else:
print("The animal is not in the list")