Python program to build flashcard using class in Python
In this article, we will see how to build a flashcard using class in python. A flashcard is a card having information on both sides, which can be used as an aid in memoization. Flashcards usually have a question on one side and an answer on the other. Particularly in this article, we are going to create flashcards that will be having a word and its meaning.
Let’s see some examples of flashcard:
- Take the word and its meaning as input from the user.
- Create a class named flashcard, use the __init__() function to assign values for Word and Meaning.
- Now we use the __str__() function to return a string that contains the word and meaning.
- Store the returned strings in a list named flash.
- Use a while loop to print all the stored flashcards.
Below is the full implementation:
- Create a class named flashcard.
- Initialize dictionary fruits using __init__() method.
- Now randomly choose a pair from fruits using choice() method and store the key in variable fruit and value in variable color.
- Now prompt the user to answer the color of the randomly chosen fruit.
- If correct print correct else print wrong.