python - using a while loop instead of for loop -


secret_word = "python" correct_word = "yo" count = 0  in secret_word:  if in correct_word:       print(i,end=" ")  else:       print('_',end=" ") 

so outcome of code _ y _ _ o _ question how can same output using while loop instead of using loop. know have use index iterate on each character when tried failed . 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

you can this:

secret_word = "python" correct_word = "yo" count = 0  while count < len(secret_word):     print(secret_word[count] if secret_word[count] in correct_word else '_', end=" ")     count += 1 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -