secret_word = "python"
correct_word = "yo"
count = 0
for i in secret_word:
if i in correct_word:
print(i,end=" ")
else:
print('_',end=" ")
so the outcome of the code will look like this _ y _ _ o _
my question is how i can i get the same output by using while loop instead of using For loop. i know i have to use index to iterate over each character but when i tried i failed . so any help?
while count < len(secret_word):
if correct_word [count]in secret_word[count]:
print(correct_word,end=" ")
else:
print("_",end=" ")
count = count + 1
Thanks
countnot indented properly. You don't needcountinsecret_wordjust use:if correct_word[count] in secret_word: