Code does not stop

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

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!”)

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

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

2 Likes

thanks for the explanation.

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