Python game. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python game.

How to write in python program: Ask the user about a letter then if it’s on the word print the letter on suitable place. For example: The word is Canada User input=d - - - - d - (how I can write like that)?

16th Nov 2019, 3:20 PM
Alshaqsia Alshaqsi
Alshaqsia Alshaqsi - avatar
4 Answers
+ 3
I tried this and it works: word = "Canada" letters = [] for i in word: letters.append(i) letter = input() whattoprint = [] for i in letters: if i == letter: whattoprint.append(i) else: whattoprint.append("-") print("".join(whattoprint)) I hope this is helpful!
16th Nov 2019, 4:08 PM
Daniel Tande
Daniel Tande - avatar
+ 2
Try this: word = 'Canada' letter = 'd' newword = '' for i in word: if i != letter: newword += '-' else: newword += i print(newword) https://code.sololearn.com/c9aHlq6kmh3b/?ref=app
16th Nov 2019, 4:56 PM
Asman-H
Asman-H - avatar
16th Nov 2019, 5:41 PM
Akash
Akash - avatar
0
it doesn’t work.
17th Nov 2019, 4:37 PM
Alshaqsia Alshaqsi
Alshaqsia Alshaqsi - avatar