From 3d91b5abe6783a605c20698ae2f69c3233cd592a Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:18:59 +0400 Subject: [PATCH 1/6] Create flashcard.py A simple flashcard program (without a GUI), that enables the user to enter questions and answers. The program asks the user the entered 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 0000000..d35e05e --- /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 + + From 9d2b4665fc4f86854425ef42ff04bf37ff63faed Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:11:16 +0400 Subject: [PATCH 2/6] Adding flashcard.py Simple Flashcard Program (without a GUI). --- flashcard.py | 56 +++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/flashcard.py b/flashcard.py index d35e05e..eef3f4a 100644 --- a/flashcard.py +++ b/flashcard.py @@ -1,29 +1,27 @@ -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 - - +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 \ No newline at end of file From 2571aa1013b990f64ac918e13c5a95b2aefb1105 Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:16:09 +0400 Subject: [PATCH 3/6] Create flashcard.py Simple Flashcard Program --- Flash Card /flashcard.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Flash Card /flashcard.py diff --git a/Flash Card /flashcard.py b/Flash Card /flashcard.py new file mode 100644 index 0000000..09a8fcf --- /dev/null +++ b/Flash Card /flashcard.py @@ -0,0 +1,27 @@ +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 From 6f813e650caa2e0149928b69fe179e5adb69f1a2 Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:18:14 +0400 Subject: [PATCH 4/6] Delete flashcard.py --- flashcard.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 flashcard.py diff --git a/flashcard.py b/flashcard.py deleted file mode 100644 index eef3f4a..0000000 --- a/flashcard.py +++ /dev/null @@ -1,27 +0,0 @@ -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 \ No newline at end of file From 7bdd613551816ce4193b24976db735d558d39dc6 Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:08:49 +0400 Subject: [PATCH 5/6] Create README.md Explanation of workings/ logic of flashcard.py --- Flash Card /README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Flash Card /README.md diff --git a/Flash Card /README.md b/Flash Card /README.md new file mode 100644 index 0000000..2f36df2 --- /dev/null +++ b/Flash Card /README.md @@ -0,0 +1,20 @@ +## Prerequisites ++ Python 3.x ++ Import of random module + +## Workings of Code ++ Imports random module --> Selective import can be done of random.choice() only ++ ++ The code uses both for and while loops ++ ++ The while loop is infinite, and option to exit the program is given to user ++ ++ User enters question and answer which is accepted via an input() ++ ++ These input question-answers are stored in a dictionary as key-value pairs (key = question, value = answer) ++ ++ After input by the user, stored questions are randomly asked to user using random.choice() from random module ++ ++ Answers are verified by calling the question stored in the dictionary ++ ++ Code ends when user inputs "n" to indicate that they wish to exit, or when every question has been asked. From a201014e602ef325de33bfa806522fb0dd405246 Mon Sep 17 00:00:00 2001 From: Nikhil2346 <141352283+Nikhil2346@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:14:05 +0400 Subject: [PATCH 6/6] Update README.md --- Flash Card /README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flash Card /README.md b/Flash Card /README.md index 2f36df2..8adf9b4 100644 --- a/Flash Card /README.md +++ b/Flash Card /README.md @@ -2,7 +2,7 @@ + Python 3.x + Import of random module -## Workings of Code +## How the code works + Imports random module --> Selective import can be done of random.choice() only + + The code uses both for and while loops