Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if, else, del issue
#1
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))
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
The del is outside of the loop. Watch your indentation!
it should be indented same as print
Reply


Forum Jump:

User Panel Messages

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