Q:

Program to build flashcard using class in Python

0

Flashcard is a virtual card that contains a word and its meaning and for each word, we define a separate flashcard. Python's class could help us in making such a type of program.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# We are making a flash card program, 
# in which each flashcard will consists 
# of a word and its meaning
# Using class in python would make it easy

# We are defining a class 'card'
class card(object):
    def __init__(self, word, meaning):
        self.word = word
        self.meaning = meaning
        
    def getmeaning(self):
        return self.meaning
    
    def __str__(self):
        return self.word + ' : ' + self.getmeaning()
  
# Defining a function for making a list of flashcards
def flashcard(flash, words, meanings):
    flash.append(card(words, meanings))
    return flash

lists = []
y = input("Want to add a flashcard? ")
while y == 'y' or y == 'Y':
    word = input("Word you want to add to your Flashcards: ")
    meaning = input("Meaning of the word in flashcard: ")
    lists = flashcard(lists, word, meaning)
    y = input("for adding another flashcard, press Y/y :")

print("----Following are the flashcards you made----")
for el in lists:
    print(el)    

Output

Want to add a flashcard? y
Word you want to add to your Flashcards: rescind
Meaning of the word in flashcard: cancel officially
for adding another flashcard, press Y/y :y
Word you want to add to your Flashcards: hegemony
Meaning of the word in flashcard: dominance over certain area
for adding another flashcard, press Y/y :y
Word you want to add to your Flashcards: brazen
Meaning of the word in flashcard: unrestrained by convention or proprierty
for adding another flashcard, press Y/y :n
----Following are the flashcards you made----
rescind : cancel officially
hegemony : dominance over certain area
brazen : unrestrained by convention or proprierty

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now