Python Forum
Help adding items to a glossary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help adding items to a glossary
#1
hey folks, I have a question for my homework where I need to add words and a definition to a glossary then make a user aware that the word/definition has been added to the glossary file so far my program works as it should, it asks the user to press a certain key to see a word from the glossary that gets imported from the csv thing then prompts the user to press enter to see the definition of the word, and also has the option to stop the program, i need to make another definition to add more but I'm so lost trying to do it can anyone help with this? code I have is below, if possible can any help be kept as low level as possible so I can understand it fully? thanks in advance people.

 # Revision_helper.py

""" this flashcard program will allow the user to prompt for a glossary index,
it will show the user one of the indexes and when the user presses return
will give a definition of the word that they can use as study material"""



from random import *
import csv 



def show_flashcard():
    """ show the user a random key and ask them the definition,
        show the correct definition once the enter key is pressed"""

    random_key = choice(list(glossary))
    print('Define: ', random_key)
    input('press return to see the correct definition')
    print(glossary[random_key])

    
def file_to_dictionary(filename):
    """ create a dictionary with the contents of a file"""
    
    file = open(filename, 'r')
    reader = csv.reader(file)
    dictionary = {}
    for row in reader:
        dictionary[row[0]] = row[1]
    return dictionary



# setup the glossary
glossary = file_to_dictionary('Glossary.txt')



# The interactive loop
exit = False
while not exit:
    user_input = input(' Enter s to show a flashcard and q to quit or n to add a new entry' )
    if user_input == 'q':
        exit = True
    elif user_input == 's':
        show_flashcard()
    else:
        print(' you need to enter either s, q or n to continue')
Reply


Messages In This Thread
Help adding items to a glossary - by lga13 - Jan-07-2019, 11:59 PM
RE: Help adding items to a glossary - by stullis - Jan-08-2019, 03:31 AM
RE: Help adding items to a glossary - by perfringo - Jan-08-2019, 06:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020