I have a program in which you get a random word, and you have to guess it by typing different letters, and it says if its in the word and in what place. But i can’t seem to figure out how to overlap 2 strings with each other. For example, in my code this error keeps happening: You have the word: apple. And you guess the letter p. So you get as an output ‘pp_’ and then you guess the letter l but instead of saying ‘ppl_’ it just says ‘__l‘.
here is the code:
while True:
Woord = input('Wat wil je dat het galgje woord wordt: ')
correct = 0
superCorrect = len(Woord)
count = 0
gokjes = 8
dood = 0
geraden_letters = ''
letterNieuw = ''
for i in range(20):
print("")
x = len(Woord)
for i in range(x):
print("_",end=' ')
for i in range(2):
print("")
for i in range(gokjes):
letter = input('Gok een letter: ')
if letter == "":
exit()
else:
if letter in Woord:
count = Woord.count(letter)
print('Correct')
for char in Woord:
if char == letter:
geraden_letters += char
correct = correct + 1
else:
geraden_letters += ''
print(geraden_letters)
if correct == superCorrect:
print('Het woord was ... ', geraden_letters.upper(),'!')
exit()
else:
print('Incorrect')
print(letter)
dood = 1
if dood == 1:
print('Het galgje is dood')
print("")
tried the letter p, got output ‘pp__’, then tried the letter l, expected output ‘ppl‘, but got ‘__l‘ instead.
benyboya2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.