#๐ Beginner Help with Python how to insert a character in a variable from a string
24 messages ยท Page 1 of 1 (latest)
@glossy sinew
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.
word_list = ["ardvark", "baboon", "camel"]
random_word = random.choice(word_list)
ask_letter = input("What is your letter?").lower()
correct_letter =
what are you trying to do?
sorry for my poor English. I'm trying to insert one of the letters in the word list into the correct_letter variable
for example, if the random_word is baboon, the correct_letter variable should get the letters from the baboon
its for a hangman project im doing
so like you want each letter of the word baboon?
yes
but it's a random word chosen off the list
so i cant just write the individual letters
ooooh i think i get it so basically
your turning the random word into a list
and if the users input is in that list they get it correct or something
?
just use list()
You can use a set to strip duplicate letters for you, if you don't care about their position.
But in your case it's probably not necessary
!e
word = "your word"
unique_chars = set(word)
print(unique_chars)```
:white_check_mark: Your 3.12 eval job has completed with return code 0.
{'y', ' ', 'u', 'r', 'd', 'o', 'w'}
ok
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.