If your inputs are "sometimes" ints and "sometimes" floats then just wrap each input in a float(). You could make something more complex, but why would you?

Answer from CambridgeCro on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_float.asp
Python float() Function
The float() function converts the specified value into a floating point 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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_float.asp
Python Float
Float, or "floating point number" is a number, positive or negative, containing one or more decimals. ... Float can also be scientific numbers with an "e" to indicate the power of 10.
Discussions

How to make python accept both int and float input???
i need my calculator to accept both the inputs in form of integer and floating point number Neeeeed Hellp ASAP More on sololearn.com
๐ŸŒ sololearn.com
161
66
How to accept only integer or float inputs?

I don't understand why you don't just use floats?

while True:
            try:
                time = float(raw_input("How much time has elapsed since your last stop (in hours)?"))
            except ValueError:
                print("Enter a valid number of hours!")
                continue

By typing an integer value, it'll just turn it into a float anyway.

More on reddit.com
๐ŸŒ r/learnpython
14
5
February 23, 2016
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ read-input-as-a-float.aspx
Read input as a float in Python
April 20, 2025 - See the program and output โ€“ ... can be used to take input as a float directly โ€“ but input string can be converted into a float by using float() function which accepts a string or a number and returns a float value....
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_user_input.asp
Python User Input
The input from the user is treated as a string. Even if, in the example above, you can input a number, the Python interpreter will still treat it as a string. You can convert the input into a number with the float() function:
๐ŸŒ
Snakify
snakify.org โ€บ integer and float numbers
Integer and float numbers - Learn Python 3 - Snakify
When we read an integer value, we read a line with input() and then cast a string to integer using int(). When we read a floating-point number, we need to cast the string to float using float(): ... Floats with very big or very small absolute ...
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-input-float
How to take Float user input in Python | bobbyhadz
April 9, 2024 - We used a while loop to only allow the user to enter a float value. The code snippet keeps prompting the user for input until they enter a valid float.
Find elsewhere
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ python โ€บ examples โ€บ faq โ€บ python-how-to-get-float-user-input
How to take Float user input in Python | Tutorial Reference
March 28, 2025 - The input() function always returns a string. The float() constructor then attempts to convert the returned string into a float.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ float-in-python
float() in Python - GeeksforGeeks
September 18, 2025 - In Python, the float() function is used to convert numbers or numeric strings into floating-point numbers. A floating-point number is simply a number with a decimal point (for example, 3.14, -0.5, or 10.0). This function is especially useful ...
๐ŸŒ
Smash Your Exams
code.smashyourexams.com โ€บ learn โ€บ learn python โ€บ input and data types โ€บ real and float input
Python float(input()) | int vs float at GCSE
float is Python's name for a real number, which is one that can have a decimal part. ... It works exactly like int(), and you read it the same way, from the inside out. input(...) produces the text "3.50", then float(...) turns that text into ...
๐ŸŒ
Davrot
davrot.github.io โ€บ pytutorial โ€บ python_basics โ€บ input_output_string_int_float
input, print, string, int, float
Return a floating point number constructed from a number or string x. If the argument is a string, it should contain a decimal number, optionally preceded by a sign, and optionally embedded in whitespace. The optional sign may be โ€˜+โ€™ or โ€˜-โ€˜; a โ€˜+โ€™ sign has no effect on the value ...
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 03-strings-input โ€บ 02-number-input
Numerical Input :: Introduction to Python
July 30, 2026 - Resources Slides 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. Hereโ€™s a quick example program that requires two inputs ...
๐ŸŒ
Cach3
w3schools.com.cach3.com โ€บ python โ€บ ref_func_float.asp.html
Python float() Function
The float() function converts the specified value into a floating point number. ... Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow Filter List Sort List ยท HTML CSS JavaScript ...
๐ŸŒ
Emeritus
emeritus.org โ€บ home โ€บ blog โ€บ coding
What is a Float in Python and How Does it Benefit Programmers
August 12, 2025 - Whenever you want to use NaN, you must use float() in a string format to convert it into a floating value. ... Strings in python are a series of characters within single or double quotes.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ how to take float input in python
How to take float input in Python - Java2Blog
February 23, 2021 - In Python 3.x, raw_input was renamed to input and the Python 2.x input was removed. ... Letโ€™s see with the help of example. ... if you want to take float as input, then you need to use float() function to explicitly convert String to float.
๐ŸŒ
Cach3
w3schools.com.cach3.com โ€บ python โ€บ gloss_python_float.asp.html
Python Float - W3Schools
Python HOME Python Intro Python Get Started Python Syntax Python Comments Python Variables Python Data Types Python Numbers Python Casting Python Strings Python Booleans Python Operators Python Lists Python Tuples Python Sets Python Dictionaries Python If...Else Python While Loops Python For Loops Python Functions Python Lambda Python Arrays Python Classes/Objects Python Inheritance Python Iterators Python Scope Python Modules Python Dates Python JSON Python RegEx Python PIP Python Try...Except Python User Input Python String Formatting
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python float: a step-by-step guide
Python Float: A Step-By-Step Guide | Career Karma
December 1, 2023 - The parameter of the input method ... to the answer our program calculated. Importantly, we use the float() method to convert the variable student_input to a float....
๐ŸŒ
YouTube
youtube.com โ€บ watch
Input in Python - The Input() Function with Float() | How to take only Float Input in Python - YouTube
Input in Python - The Input() Function with Float() | input function in python | Float() function | How to take only Float Input in PythonSimilar to the inte...
Published: October 20, 2024
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_numbers.asp
Python Numbers
x = 1 # int y = 2.8 # float z = 1j # complex #convert from int to float: a = float(x) #convert from float to int: b = int(y) #convert from int to complex: c = complex(x) print(a) print(b) print(c) print(type(a)) print(type(b)) print(type(c)) Try it Yourself ยป ยท Note: You cannot convert complex numbers into another number type. Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers: