How do I decrement? (Your own while/else)


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096#

Make sure to decrement guesses_left!

I am not sure how to decrement that statement>

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
while guesses_left > 0:
    guess = random.randint(1,10)
    if guess == 7:
        print "You win! "
        break
    guesses_left +=1
else:
    print "You lose "


#2

You are pretty close! Let's get a few things clarified.

  1. What does "decrement" mean? Once you figure that out, what symbol is used on the statement you wrote for guesses_left?

  2. In the instructions #2, it says this:

    Ask the user for their guess, just like the second example above.

  3. (continued on from number 2) It is to be placed after the while statement. The "second example above" that is mentioned is this: guess = int(raw_input("Your guess: ")). You will want to rewrite your original guess variable with that.

  4. Finally, the hint section tells you this:

    The if should check if guess == random_number

Hope that clarifies it. Let us know if it worked!


#3

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