# Day 022 - Project 22 : Totally Random Million-to-One

If you have any questions, comments or issues with this project please post them here!

Guess the number between one and 1Million!! Closest guess gets a shout-out from Replit team @LessonHacker and @AarrrMe!

Day 22 of #Replit100DaysOfCode #100DaysOfCode.

2 Likes
``````print("What's my number?")

import random
guess=random.randint(1,10)
guess_no = 0

while True:
myNumber=5
if guess<=myNumber:
print("Too high, try again.")
guess_no += 1

elif guess <= myNumber:
print("Too low, try again.")
guess_no += 1

else:
if guess == myNumber:
print("Yippee, you got it in" , guess_no)
``````

I need help, Iâ€™m not ashamed to admit itâ€¦ this just created an endless loop and I donâ€™t know whyâ€¦

So you used `<=` which means less than or equal to. So when your guess is lower than the number or you guessed correct, it says â€śToo high, try again.â€ť

Instead the code should be more like:

``````import random

number = random.randint(1, 1_000_000)
guess = 0
guessNumber = 0

while guess != number:
if guess > number:
print("Too high, try again.")
else:
print("Too low, try again.")

guessNumber += 1

print("Yippee, you got it in", guessNumber)
``````
1 Like

this produces another loop of either â€śToo low, try againâ€ť or â€śToo high, try againâ€ť depending on what the number is.

• I"m not getting itâ€¦ did it work for you?

I somehow forgot to get the userâ€™s input.

``````import random

number = random.randint(1, 1_000_000)
guess = 0
count = 0

print("Guess the number!")

while guess != number:
guess = int(input("\nEnter a number > "))

if guess > number:
print("Too high, try again.")
elif guess < number:
print("Too low, try again.")

count += 1

print("Yippee, you got it in", count)
``````

1 Like

oh man, I totally missed the point there, I thought the user had to generate a new random number each time and if somehow the number they generated matched my number they were correct. When really they had to match the random number that was generated at the start.

â€śMake the number generator completely random between 1 and 1,000,000. Now, the game will always have the user guess a random number each time (now the user canâ€™t cheatâ€¦)â€ť

I read that as guessing a random number each time they guessed, not each time the game was played.

Thanks so much for your help.

2 Likes