Below is one part of a basic script that I have written whilst tinkering with Python. What I intend for this script to do is prompt me for the subject of my note, then asks me to confirm my selection. If for whatever reason I've selected the wrong subject I have incorporated a while loop that would repeat until my selection is correct. The result of the script would be that it would return the confirmed subject.
The problem which occurs when I execute the script is that when I reply with 'no' (or anything else which designates that I do not confirm that this is the correct selection) the terminal output spams me with the list of subjects repeatedly. The only way to terminate this is by KeyboardInterrupt.
How do I resolve this? I feel it may have something to do with the iteration statement in the while loop, or inadequate placement of the break statement.
Thank you for your your help.
def subject():
subject_dict = {1: 'Mathematics', 2: 'Computer Science', 3: 'English Literature & Language', 4: 'Philosophy', 5: 'Linguistics', 6: 'Art & Design'}
subject_prompt = ("\nSelect the subject of your note.\n")
print(subject_prompt)
for i in subject_dict:
subject_choices = str(i) + ". " + subject_dict[i]
print(subject_choices)
subject_prompt_input = input("\n> ")
x = int(subject_prompt_input)
confirmation = input("\nSo the subject of your note is" + " '" + subject_dict[x] + "'" + "?\n> ")
while confirmation in ['no', 'No', 'n', 'NO']:
print(subject_prompt)
for i in subject_dict:
subject_choices = str(i) + ". " + subject_dict[i]
print(subject_choices)
subject_prompt_input
confirmation
if confirmation in ['quit', 'stop', 'exit']:
quit()
if confirmation in ['Yes', 'YES', 'yes', 'y', 'Y']:
break
if confirmation in ['yes', 'y', 'YES', 'Y']:
selection = subject_dict[x]
return selection
confirmationinside the loop.confirmation.lower(), so you only have to check againstyoryesandnorno.