Code does not stop


#1



print("lets start coding")
word="Harry potter"
pos=0
guess=input("Guess a word:")

while guess!=word and pos< len(word):
    print("you guessed it wrong,hint first letter:", end='') 
    print(pos+1,"is:", word[pos] +".", end='' )
guess=input("guess again")
pos=pos+1
if pos==len(word) and word!=guess:
   print("you dint guessed it right & answer is:", word +'.')
else:
      print("\n you guessed it right after", pos+1, "guesses!")


In this code when i run it does not stop.kindly explain what is wrong with the above code.Am new at python coding


#2

these lines:

guess=input("guess again")
pos=pos+1
if pos==len(word) and word!=guess:
   print("you dint guessed it right & answer is:", word +'.')
else:
      print("\n you guessed it right after", pos+1, "guesses!")

are not inside the loop

so, your loop currently only prints stuff, pos doesn't change in the loop, so you have an infinity loop


#3

thanks for the explanation.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.