From 5a20cf03daadc72b30edf1f4b582ab13706acf38 Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:02:42 +0400 Subject: [PATCH] Create flashcard.py A simple flashcard program (without a GUI), that enables the user to enter questions and answers. The program asks them the questions randomly, and checks their accuracy. --- flashcard.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 flashcard.py diff --git a/flashcard.py b/flashcard.py new file mode 100644 index 00000000..d35e05e7 --- /dev/null +++ b/flashcard.py @@ -0,0 +1,29 @@ +import random +num_questions = int(input("Enter number of questions: ")) +q_solutions = dict() # creates an empty dictionary +count = 0 # counts the number of questions asked +for i in range (num_questions): + question = input("Enter your question: ") + answer = input("Enter your answer: ") + q_solutions[question.lower()] = answer.lower() # adding the key-value pair to dictionary + print("\n") +q_s = list(q_solutions.keys()) +while True: + q = random.choice(q_s) # picks a random key from the question and answer dictionary + count+=1 # increments the count variable, to indicate that a question has been asked + print(q) + ans = input("Enter an answer for the above question: ") + if ans.lower() == q_solutions[q]: + print("You're right!") + else: + print("You're wrong! \nThe correct answer is:",q_solutions[q]) + q_solutions.pop(q) # removes the question-answer pair that has been asked to prevent repetition + if count > len(q_solutions): + print("All questions have been asked.") + break + choice = input("\nDo you wish to continue? Enter Y OR N: ") + print() + if choice.lower() == 'n': + break + +