Your own while / else


#1



I am stuck on:
https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096
And I would like some help :stuck_out_tongue:
Please help? :ear_of_rice:


from random import randint
random_number = randint(1, 10)
def random():
    guesses_left = 3
    count = 0
    while guesses_left > 0:
        guess = int(raw_input("Guess a # 1-10: "))
        num = random.randint(1, 6)   
        if num == 6 or num == 1:
            print "You win!"
            break
        else:
            guesses_left -= 1
            print "You lose."


#2

:stuck_out_tongue: I Need Help PLEASE!!!!!!!!???????? :stuck_out_tongue:


#3

Hi, I think you don't need to define a function for this exercise. Instructions tell you to use just a while loop.


#4

No need to define a function for this.

Why do you need the count variable?

The from...import statement
When you import a specific function from a module, use only the function's name, for example, randint(1, 10), not random.randint(1, 10).

The instructions don't say that the player wins if num equals 6 or 1.

Please read the instructions once again and code it accordingly.


#5

Few days later, still stuck.


#6

Few more days later... Still stuck ---- -_-


#7

Fffffaaarrrggggllleeeeeeeeeeeeeeeeee Fargle :stuck_out_tongue:


#9

Correct code:

from random import randint

random_number = randint(1, 10)

guesses_left = 3
while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    if guess == random_number:
        print "You win!"
        break
    guesses_left -= 1
else:
    print "You lose."

Should work! :wink:


#10

Thanks... :stuck_out_tongue_winking_eye:


#11

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