input()




input([prompt]) Accepting user input

prompt: (optional) String ( message ) to be shown to user
Input box for users

Getting user input in Python & printing output after converting into integer by using int() function


Displaying input box to accept user inputs

x1=input("Enter first number: ")
x2=input("Enter second number: ")
print("Total :",x1+x2)
Output
Enter first number: 3
Enter second number: 4
Total : 34
Why the output is not equal to 7 with input of 3 and 4 as input numbers ?

As all user inputs are string data type ( by default ) , we have to convert the type by using int()
x1=int(input("Enter first number: "))
x2=int(input("Enter second number: "))
print("Total :",x1+x2)
Output
Enter first number: 3
Enter second number: 4
Total : 7

Float input

Used float() to convert string to float data type.
x1=float(input("Interest Rate is : "))
print ("interest rate ",x1)
Output
Interest Rate is : 5.6
interest rate  5.6
sum=0
for i in range(3):
    x1=int(input('Enter a number'))
    sum=sum+x1
print("Sum : ", sum)


What is the sum of two numbers provided by the user, and how can we ensure valid numerical input?
def get_number(message):
    while True:
        user_input = input(message)

        try:
            number = float(user_input)
            return number
        except ValueError:
            print("Invalid input. Please enter a number only.")


num1 = get_number("Enter first number: ")
num2 = get_number("Enter second number: ")

total = num1 + num2

print("The sum is:", total)
Try running the code and enter 30.4 as the first number and 50.3 as the second number. Then, analyze the output.
All Built in Functions in Python dir() ord()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer