Your third attempt is correct - but what is happening to guess_row before/after this code? For example, consider the following:

a = "Hello"
try:
    a = int(input("Enter a number: "))
except ValueError:
    print("Not an integer value...")
print(str(a))

If you enter a valid number, the final line will print out the value you entered. If not, an exception will be raised (showing the error message in the except block) and a will remain unchanged, so the final line will print "Hello" instead.

You can refine this so that an invalid number will prompt the user to re-enter the value:

a = None
while a is None:
    try:
        a = int(input("Enter a number: "))
    except ValueError:
        print("Not an integer value...")
print(str(a))
Answer from user4200092 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-take-integer-input-in-python
How to take integer input in Python? - GeeksforGeeks
April 3, 2026 - Interview Questions · Examples ... input() function always returns a string. To take integer input, the string must be typecast into an integer using the int() function....
🌐
Real Python
realpython.com › python-input-integer
How to Read Python Input as Integers – Real Python
March 18, 2026 - You’re going to leverage Python’s own error-handling mechanism. By default, the integer conversion will throw a ValueError exception if it fails. Try the above code again, but this time, notice how it behaves with bad input: ... >>> number_as_string = input("Please enter an integer: ") Please enter an integer: rutabaga >>> number_as_integer = int(number_as_string) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: 'rutabaga'
Discussions

I'm new to python: convention question
I’m new to python. I wanted to know if when I use the input command, is it common to write the type of variable we expect to recieve from the input? For example: · We aren’t “writing the type of variable” here. Python’s names (we like to call them names, rather than “variables”) ... More on discuss.python.org
🌐 discuss.python.org
4
0
July 14, 2023
python - How can I read inputs as numbers? - Stack Overflow
Why are x and y strings instead of ints in the below code? (Note: in Python 2.x use raw_input(). In Python 3.x use input(). More on stackoverflow.com
🌐 stackoverflow.com
python - why does "int" come before "input"? I would like to understand the logic of this code - Stack Overflow
I know temp var isn't in the original, somebody edited the question. 2024-01-07T23:26:14.187Z+00:00 ... I edited the code here to make it clear that integer_number is only assigned to at the end. Actually python uses its stack to store temp_var and not a named variable. 2024-01-12T17:29:54.987Z+00:00 ... @pippo1980 What do you mean? There are no functions being passed around here. Maybe you misread it as something like temp_var = input... More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to make input() accept strings and integers?
Instead of casting input straight into an integer you can wait and check if it's done first. Instead of: grade = int(input("Enter grade: ")) Do this: grade = input("Enter grade: ") if grade.lower() == 'done': print("Done.") else: integer_grade = int(grade) More on reddit.com
🌐 r/learnpython
6
3
October 8, 2021
🌐
Hyperskill
hyperskill.org › university › python › input-and-input-in-python
Python input() Function: Get User Input with Examples
June 5, 2026 - When you use the input() function ... typing '123' is seen as the string '123'. On the hand for integer input you need to change the string input into an integer using the int() function....
🌐
Python.org
discuss.python.org › python help
I'm new to python: convention question - Python Help - Discussions on Python.org
July 14, 2023 - I’m new to python. I wanted to know if when I use the input command, is it common to write the type of variable we expect to recieve from the input? For example: num = int(input()) The other option: just num=input() …
🌐
w3resource
w3resource.com › python-exercises › python-basic-exercise-10.php
Python: Input an integer (n) and computes the value of n+nn+nnn - w3resource
May 17, 2025 - A base-n literal consists of the digits 0 to n-1, with a to z (or A to Z) having values 10 to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, ...
Top answer
1 of 10
407

Since Python 3, input returns a string which you have to explicitly convert to int, like this

x = int(input("Enter a number: "))
y = int(input("Enter a number: "))

You can accept numbers of any base like this

>>> data = int(input("Enter a number: "), 8)
Enter a number: 777
>>> data
511
>>> data = int(input("Enter a number: "), 16)
Enter a number: FFFF
>>> data
65535
>>> data = int(input("Enter a number: "), 2)
Enter a number: 10101010101
>>> data
1365

The second parameter tells it the base of the number and then internally it understands and converts it. If the entered data is wrong it will throw a ValueError.

>>> data = int(input("Enter a number: "), 2)
Enter a number: 1234
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: invalid literal for int() with base 2: '1234'

For values that can have a fractional component, the type would be float rather than int:

x = float(input("Enter a number:"))

Differences between Python 2 and 3

Summary

  • Python 2's input function evaluated the received data, converting it to an integer implicitly (read the next section to understand the implication), but Python 3's input function does not do that anymore.
  • Python 2's equivalent of Python 3's input is the raw_input function.

Python 2.x

There were two functions to get user input, called input and raw_input. The difference between them is, raw_input doesn't evaluate the data and returns as it is, in string form. But, input will evaluate whatever you entered and the result of evaluation will be returned. For example,

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

The data 5 + 17 is evaluated and the result is 22. When it evaluates the expression 5 + 17, it detects that you are adding two numbers and so the result will also be of the same int type. So, the type conversion is done for free, and 22 is returned as the result of the input and stored in the data variable. You can think of input as the raw_input composed with an eval call.

>>> data = eval(raw_input("Enter a number: "))
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

Note: You should be careful when you are using input in Python 2.x. I explained why one should be careful when using it, in this answer.

But, raw_input doesn't evaluate the input and returns as it is, as a string.

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = raw_input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <type 'str'>)

Python 3.x

Python 3.x's input and Python 2.x's raw_input are similar and raw_input is not available in Python 3.x.

>>> import sys
>>> sys.version
'3.4.0 (default, Apr 11 2014, 13:05:11) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <class 'str'>)
2 of 10
54

In Python 3.x, raw_input was renamed to input and the Python 2.x input was removed.

This means that, just like raw_input, input in Python 3.x always returns a string object.

To fix the problem, you need to explicitly make those inputs into integers by putting them in int:

x = int(input("Enter a number: "))
y = int(input("Enter a number: "))
Find elsewhere
🌐
W3Schools
w3schools.com › python › ref_func_int.asp
Python int() Function
The int() function converts the specified value into an integer number. ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
🌐
YouTube
youtube.com › watch
How to take int input in Python — safely and correctly - YouTube
Trying to get numeric input from your user? If you're running int on the result of the input function, then you're likely going to have problems. How can we ...
Published: July 13, 2025
🌐
EyeHunts
tutorial.eyehunts.com › home › how to take n number of inputs in python | example code
How to take n number of inputs in Python | Example code
October 25, 2023 - n = int(input("Enter the number of inputs: ")) inputs = [input(f"Enter input {i + 1}: ") for i in range(n)] print("You entered:", inputs) Do comment if you have any doubts or suggestions on this Python input topic.
Top answer
1 of 5
7
integer_number = int(input("something here"))

is just an abbreviated way of saying:

temp_var = input("something here")
integer_number = int(temp_var)

It is not the other way around, because the int() function takes a string and converts it into an int. If you did it the other way around, the function wouldn't have anything to convert.

2 of 5
2

In Python you can pass functions as arguments of another function and of course they'll be evaluated before the outer function. Guess I should point you to the relevant official Python documentation that states that, but just googling for it isn't working right now.

See Python’s Functions Are First-Class:

Python's functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions.

Got a nice answer about that on SO :

What are "first-class" objects:

In short, it means there are no restrictions on the object's use. It's the same as any other object.

A first class object is an entity that can be dynamically created, destroyed, passed to a function, returned as a value, and have all the rights as other variables in the programming language have.

Your one is not the first question about that:

All arguments are evaluated before the function is called:

Answer:

You are right, all arguments are evaluated before the function is called, otherwise the function cannot know what is passed to it. So what you are doing is actually:

but no link to docs here too.

Took a while, I found it here:

6.3.4. Calls its the link for Python 3:

...............All argument expressions are evaluated before the call is attempted. Please refer to section Function definitions for the syntax of formal parameter lists.........

🌐
Pierian Training
pieriantraining.com › home › python tutorial: how to take an integer input in python
Python Tutorial: How to take an integer input in Python - Pierian Training
April 12, 2023 - Therefore, you would need to explicitly convert the input to an integer using `int()`. In conclusion, taking integer input in Python is a simple task that can be accomplished using the `input()` function. However, it is important to note that the `input()` function returns a string value even if the user inputs an integer.
🌐
W3Schools
w3schools.com › python › python_user_input.asp
Python User Input
The following example asks for your name, and when you enter a name, it gets printed on the screen: ... Python stops executing when it comes to the input() function, and continues when the user has given some input. In the example above, the user had to input their name on a new line.
🌐
Quora
quora.com › What-is-the-difference-between-int-input-and-input-int-in-Python
What is the difference between 'int (input()) and input (int())' in Python? - Quora
Answer (1 of 4): Dear Shiva, Lets write some code to understand it thoroughly. [code]# question - take a number as input and print it's thrice #it is simple right num = int(input("enter num")) #here when the input function takes an input it is in a string format hence we need conversion because...
🌐
Kansas State University
textbooks.cs.ksu.edu › intro-python › 03-strings-input › 02-number-input
Numerical Input :: Introduction to Python
July 30, 2026 - Of course, we can also read numerical input in Python using the input() function. To do this, we must simply use either the int() or float() function to convert the input received as a string to the correct data type.
🌐
101 Computing
101computing.net › home › python challenges › python tip: validating user input as number (integer)
Python Tip: Validating user input as number (Integer) - 101 Computing
July 14, 2025 - To use them as integers you will need to convert the user input into an integer using the int() function. e.g. ... This line of code would work fine as long as the user enters an integer.
🌐
YouTube
youtube.com › watch
Python Tutorial: Integer Input - YouTube
Unlock the power of handling integer input in Python with our comprehensive tutorial! In this video, we delve into how to efficiently read and process intege...
Published: June 25, 2024