Program to build flashcard using class in Python

Here, we are implementation a Python program to build flashcard using class and object approach in Python.
Submitted by Anuj Singh, on May 12, 2020

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.