0

I tried using int() to convert the input into int, but I just get a TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'. How do i solve this?

import random number = random.randint(1, 50) lives = 10 guess = int(print("Enter a number between 1 and 50: ")) while guess != number and lives != 0: if guess > number: guess = int(print("Your guess is higher than the secret number. Enter another guess: ")) lives -= 1 else: guess = int(print("Your guess is lower than the secret number. Enter another guess: ")) lives -= 1 if guess == number: print("You win!") else: print("You lose!") 
2
  • 1
    print() will just output a value but not take user input. Use input() instead Commented Apr 12, 2021 at 3:34
  • int(input('Say something')) Commented Apr 12, 2021 at 3:35

4 Answers 4

1

Doesn't print() just show some text?

Try using:

guess = int(input("Enter a number between 1 and 50: ")) 

https://www.geeksforgeeks.org/taking-input-in-python/

Sign up to request clarification or add additional context in comments.

Comments

0
guess = int(input("Enter a number between 1 and 50: ")) 

By default input takes everything as a string. And we convert the type afterwards.

Comments

0

guess = int(print("Enter a number between 1 and 50: ")) is wrong. it should be

guess = int(input('enter a number between 1 and 50: ')) 

Comments

0

You are attempting to cast the output of print() to int when, as the error message suggests, print() outputs None.

If you replace the line 6 "print" with "input" your code will work (as seems expected) with python 3.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.