Oct-26-2019, 12:36 PM
Hi,
This is a working hangman code, I am struggling to understand how it work,
hope someone here can help me to clarify the 3 questions I have below so I understand the while loop better.
The following codes is an image of the codes:
![[Image: 0Y8vAHWHV]](https://www.screencast.com/t/0Y8vAHWHV)
By referring to the above code, I have 3 basic loop questions below:
1) The program start by checking the first IF, if this doesn't match it will go to the next ELIF and if that also doesn't match it will go to the ELSE.
Regardless of what's the outcome of the first 3 conditions, the code will run the last IF statement.
2) Let's just say if the first IF condition meets, it will then execute the following and then repeat the while loop again, is that correct?
if letter.upper() in lstGuessed:
letter = ''
print("Already guessed!!")
3) The only time when the program will exit the while loop is when the last IF statement matches, correct?
Thanks in advance!
This is a working hangman code, I am struggling to understand how it work,
hope someone here can help me to clarify the 3 questions I have below so I understand the while loop better.
The following codes is an image of the codes:
By referring to the above code, I have 3 basic loop questions below:
1) The program start by checking the first IF, if this doesn't match it will go to the next ELIF and if that also doesn't match it will go to the ELSE.
Regardless of what's the outcome of the first 3 conditions, the code will run the last IF statement.
2) Let's just say if the first IF condition meets, it will then execute the following and then repeat the while loop again, is that correct?
if letter.upper() in lstGuessed:
letter = ''
print("Already guessed!!")
3) The only time when the program will exit the while loop is when the last IF statement matches, correct?
Thanks in advance!