Guess the number

so i have an assignment in my class guess the number this is my code so far buy I need to make it so that it tells me higher or lower each guess can someone please fix it for me thanks

import random

print ( "Here are the rules: \n'Guess a number between 1 and 100. We'll give you a hint if you need one.'" )

num = int (random.randint( 1 , 100 ))

print (num)

guess_count = int ( 1 )

guess = int ( input ( "Guess a number! " ))

while guess ! = num:

guess_list = guess_count + 1

if guess < = 0 :

print ( "Out of Bounds. Try again." )

if guess > 100 :

print ( "Out of Bounds. Try again." )

guess = int ( input ( "Guess again: " ))

if guess = = num:

print ( "You've won! It took you %d tries, but you got it. " % (guess_count))

2 Likes

You have an if clause that tells you you’ve won when the guessed number is equal to the randomly selected one. So you need to add remaining cases (conditions) using comparison (less then, greater then).

You also don’t have to wrap randint() in int(), as randint already returns an integer in a given range.

2 Likes