I'm working on a programming project where I have to create an FAQ that allows the user to add new entries as well as delete existing entries. So far all the functions work correctly, but I am running into an issue. After the user selects to add a new entry, the entry is added successfully. However, if they choose the option to add another entry, the program just loops as if it doesn't call the function again. I've read through my textbook sources and did some searching online but could not find a solution. I also have an issue getting the exception to print my statement, but that is not a critical factor. I'm not looking for a direct answer that I can just copy into the code, just an example to go off of. Any help is greatly appreciated. Code follows below:
import pyinputplus as pyip
# Defines variables used in program
done = False #loop for input on menu
userQuestion = ''
userAnswer = ''
# Creates the menu for user interacion
menu = '''
===========================
Frequently Asked Quesstions
===========================
1: Exit
2: List FAQ's
3: Add FAQ
4: Delete FAQ
'''
###############################################
# Creates dictionary and sets default values for FAQ for functionality
faq = {
'North Korea': 'Is afraid of clowns',
'Climate change': 'It is a lie.',
'America': 'Is burning.'
}
###############################################
# Function that prints a list of the current FAQs
def display_Faq():
print('\nFrequently Asked Questions\n==========================')
for question in faq:
print('Question: ', question, '\nAnswer: ', faq[question], '\n')
print()
###############################################
# Function that adds to the FAQ based on user input
def Add_Faq():
global userQuestion
global userAnswer
while userQuestion not in faq:
try:
userQuestion = input('\nPlease enter a question for the FAQs: ')
userAnswer = input('\nPlease enter the answer: ')
faq[userQuestion] = userAnswer
print('\nEntry has been added to the FAQs.')
break
except:
print(str(userQuestion) + ' already exists in FAQs, please rephrase.\n')
###############################################
# Function that checks user input against FAQ and deletes entries
def Del_Faq():
global userQuestion
userQuestion = input('\nEnter an entry to delete: ')
if userQuestion in faq:
del faq[userQuestion]
print(str(userQuestion) + ' has been deleted from the FAQs')
else:
print(str(userQustion) + ' not exist in the FAQs, no changes have been made.')
###############################################
# Actual program that runs based off user input
while not done:
print(menu)
try:
selection = pyip.inputInt(prompt = '\nPlease enter menu item 1-4: ', min=1, max=4)
if selection == 1:
done = True
elif selection == 2:
display_Faq()
elif selection == 3:
Add_Faq()
elif selection == 4:
Del_Faq()
except pyip.PyInputPlusException:
print('Please check your input and try again')
continue