Python Forum
if, else, del issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: if, else, del issue (/thread-11597.html)



if, else, del issue - elliottmoore1 - Jul-17-2018

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))



RE: if, else, del issue - ichabod801 - Jul-17-2018

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.


RE: if, else, del issue - Larz60+ - Jul-17-2018

The del is outside of the loop. Watch your indentation!
it should be indented same as print