# Your own while / else

#1

I am stuck on:
And I would like some help

``````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

#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.

#5

Few days later, still stuck.

#6

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

#7

Fffffaaarrrggggllleeeeeeeeeeeeeeeeee Fargle

#9

Correct code:

``````from random import randint

random_number = randint(1, 10)

guesses_left = 3
while guesses_left > 0:
if guess == random_number:
print "You win!"
break
guesses_left -= 1
else:
print "You lose."``````

Should work!

#10

Thanks...

#11

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