Question: Can you please help me to amend the code below, to show y for Yes or n for No. i.e., correct = input(Did you know
Can you please help me to amend the code below, to show y for Yes or n for No.
i.e., correct = input("Did you know the definition? (Enter y for yes or n for no)")
**I also need the program to quit once the number of cards =0**
**If you see any mistakes or unnecessary code please let me know**
from random import * import csv def file_to_dictionary(filename): """ Return a dictionary with the contents of a file """ file = open(filename, 'r') reader = csv.reader(file) dictionary = {} for row in reader: dictionary[row[0]] = row[1] return dictionary def show_flashcard(): key_list = list(glossary) random_key = choice(key_list) print (random_key) input("") print (glossary[random_key]) print ("") correct = input("Did you know the definition? (Enter y for yes)") if correct == "y": print ("Now you know the definition that flashcard will be removed.") del glossary[random_key] dict_length = len(glossary) print (str(dict_length) + ' cards remain.') glossary = file_to_dictionary('TM112_Glossary.txt') exit = False while exit == False: user_input = input("Enter s to show flashcard and q to quit > ") if user_input == "q": exit = True elif user_input == "s": show_flashcard()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
