8/19 unintended repeat of prompt


#1

Hello. I used the following code for part 8:

while guesses_left >=0:
  guess= int(raw_input("your guess:"))
  if guess==random_number:
    print "You win!"
    break
  else:
    print "Try again"
  guesses_left -= 1
else:
  print "You lose"

the console shows

your guess:2
Try again
your guess:Try again
your guess:1
Try again
your guess:Try again
You lose

May I know why my code prompted the “your guess: Try again” bits


#2

Also noticed that I only got 2 input tries. And that I should’ve made guesses_left>0


#3

The course passed the code I wrote, just in case it was needed to be known.


#4

with this changes, i get:

your guess: 3
Try again
your guess: 2
Try again
your guess: 2
Try again
You lose

your guess and try again never appear on the same line.

Might be a glitch in the exercise, what if you try it here:

https://repl.it/@stetim94/DarkgreyPoliticalHeron


#5

Works fine there. May I assume that my code wasn’t being faulty then?


#6

yes, you may. In fact, i can assure you


#7

Thank you for your time.


#8

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