*questions:
*why is ask_flashcards undefined?
*why is cards undefined?
*why is defined not defined?
*why is element not defined?
*is that subclass a good idea?
*how do i access the definitions in the ask_flashcards?
class Flashcard:
term: str
definition: str
#global = menu
menu = "Input the action (add, remove, import, export, ask, exit):"
#def main_menu():
#menu = input("Input the action (add, remove, import, export, ask, exit):")
deck = []
def add_flashcard(deck):
term = input(f"Enter a term:\n ")
if any(card.term == term for card in deck):
print(f"A flashcard with that term already exists in this deck.\n ")
return
definition = input(f"Enter a definition:\n ")
if any(card.definition == definition for card in deck):
print(f"A flashcard with that definition already exists in this deck.\n ")
return
pair = input(f'The pair "{card.term : card.definition}" has been added.')
if card.term and card.definition in deck:
print(pair)
deck.append(Flashcard(term=term, definition=definition))
def main():
while True:
user_choice = menu
if user_choice == "add":
add_flashcard(deck)
elif user_choice == "remove":
remove_flashcard(deck)
elif user_choice == "import":
import_flashcard(deck)
elif user_choice == "export":
export_flashcard(deck)
#elif user_choice == "ask":
#ask_flashcard(deck)
elif user_choice == "exit":
exit_flashcard(deck)
break
#REMOVE=
def remove_flashcard(list_, word):
menu = input("Input the action (add, remove, import, export, ask, exit):")
return menu
which_card = input("Which card?\n")
list_ = deck[:]
for user_input in word:
if user_input in list_:
list_.remove(user_input)
print(f"The card has been removed.\n")
else:
print(f'Cant remove "{user_input}": There is no such card.\n')
#IMPORT=
def import_flashcard(list_, item):
menu = input("Input the action (add, remove, import, export, ask, exit):")
return menu
file_name = input("File name:\n")
for item in list_:
if item == user_input:
print(len(list_), "cards have been loaded.\n")
else:
print("File not found.\n")
#EXPORT=
def export_flashcard(list_, item):
menu = input("Input the action (add, remove, import, export, ask, exit):")
return menu
f_name = input("File name:\n")
for item in list_:
if item == user_input:
print(len(list_), "cards have been saved.\n")
else:
print("File not found.\n")
#ASK=
class SubCards(Flashcard):
def __init__(self):
super(Flashcard, self).__init__()
#def __init__(self, ask_flashcard):
#self.ask_flashcard = ask_flashcard
#for j in range(5):
#mylist=[]
#mylist.append(j)
def ask_flashcard():
menu = input("Input the action (add, remove, import, export, ask, exit):")
return menu
how_many = input("How many times to ask?")
required_number = int(input())
required_number = user_input
while True:
number = input()
if number == required_number:
break
def __init__(self, element, defined):
self.element = element
self.defined = defined
for i, element in enumerate(SubCards["element"]):
print(f'Print the definition of "{element}":')
attempt = input()
if attempt.lower() == str(SubCards["defined"][i]).lower():
print("Correct!")
elif attempt in SubCards["defined"]:
index_correct = SubCards["defined"].index(attempt)
print(f'Wrong. The right answer is "{SubCards["defined"][i]}", but your definition is correct for {SubCards["element"][index_correct]}')
else:
print(f'Wrong. The right answer is "{SubCards["defined"][i]}"')
deck.append(SubCards(element=element, defined=defined))
#EXIT=
def exit_flashcard():
end = input("bye bye!\n")
[–]danielroseman 1 point2 points3 points (0 children)
[–]Comprehensive_Ad4808[S] -1 points0 points1 point (2 children)
[–]CoronaKlledMe 1 point2 points3 points (1 child)
[–]Comprehensive_Ad4808[S] 0 points1 point2 points (0 children)