Python Forum

Full Version: if, else, del issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have written If Else code which is suppose to only delete the item from the dictionary I have created if I enter 'y'. If I press 'n' the item is still deleted. Can anyone advise please.


if user_input == 'n':
    show_word()
elif user_input =='y':
    print ('This entry has been removed, as you know the definition')
del glossary[random_key]
print (len(glossary))
Please use python tags when posting code. Otherwise we can't see the indentation, which is very likely a problem here. See the BBCode link in my signature for instructions on how to do this.
The del is outside of the loop. Watch your indentation!
it should be indented same as print