1

new to coding

was trying to make a number generator game where you guess a number and it says if it is higher or lower

however i am having issues with the code: an if statement which depends on the input and says if the number is higher or lower. Any answers would be greatly appreciated.

if input > x:
   print('smaller')
   if input == x:
        print('correct')
decorator-factory
  • 2,733
  • 13
  • 25
  • 1
    `input() != input` – Sayse Jun 04 '22 at 20:25
  • 1
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – JMA Jun 05 '22 at 00:07

3 Answers3

1

input() returns a string, so you have to convert it to an integer.

guess = int(input('Enter your guess: '))
if guess < x:
    print('your guess is smaller')
John Gordon
  • 29,573
  • 7
  • 33
  • 58
1

Welcome, Amar. Building on John's response.

# declare the number say 80

x = 80
guess = int(input('Enter your guess: '))

if guess < x:
    print('your guess is smaller')
elif guess > x:
    print('your guess is greater')
else:
    print('You have guessed the correct number')

I hope this helps!

0

Make the input type to a integer

Guess = int(input('enter your number's))
Alexander
  • 16,091
  • 5
  • 13
  • 29