#๐Ÿ”’ not understanding a snippet

17 messages ยท Page 1 of 1 (latest)

shell cobaltBOT
#

@twilit cradle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vernal radish
#

is there anything there you're unfamiliar with?

#

Do you understand loops? Enumerate? Join?

#

so what about this are you unsure of?

#

it also looks like your last print shouldn't be indented into the loop

#

!e

word = 'elephant'
display_word = ['_'] * len(word)
print(display_word)
shell cobaltBOT
vernal radish
#

let's pretend the word we're trying to guess is elephant

#

this is what display_word looks like initially

#

let's pretend we guess "e"

#

this loop is going through and updating all the positions where "e" should be in the list

#
['e', '_', 'e', '_', '_', '_', '_', '_']
#

so we would end up with this

#

index is the current position of each letter as we loop through the word

#

so whenever we have a match of guess and letter, we know where to update the list

shell cobaltBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.