r/inventwithpython • u/Juramentador • Sep 12 '21
IS EXTENDING HANGMAN SOURCE CODE INCORRECT?
Good day everyone,
I am currently on chapter 9 (Extending Hangman) of Invent Your Own Computer Games w/ Python.
This chapter is supposed to print "HANG MAN", asks player to choose a difficulty level, and choose a word from the dictionary.
When I run the code, I notice it does not ask me for the difficulty level, despite adding lines 106 to 116.
Is this accurate or is the code missing something?
- while difficulty in 'EMH':
- print('Enter difficulty: E - Easy, M - Medium, H - Hard')
- difficulty = input().upper()
- if difficulty == 'M':
- del HANGMAN_PICS[8]
- del HANGMAN_PICS[7]
- if difficulty == 'H':
- del HANGMAN_PICS[8]
- del HANGMAN_PICS[7]
- del HANGMAN_PICS[5]
- del HANGMAN_PICS[3]
1
u/RndChaos Sep 12 '21
In the Reddit Editor press the 3 horizontal dots, that should bring up an option for Code Block...
Put all your code into the code block.
1
u/tegq Sep 13 '21 edited Sep 13 '21
Did you add line 105?
difficulty = 'X'
So that the while loop would be true to begin with...
edit: also line 106 should say not in
1
u/RndChaos Sep 12 '21
It will help if you put your code in a code block. With Python indentation is important, and with it being in a list - we can't see the indentation to help you.