How to Add Input in Python
To add user input in Python, you can use the input() function.
The following examples show how to add input in Python using two different methods.
Adding Integer Input
We can add integer input in Python using the input() function along with the int() function:
# Take user input
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
# Add user numbers
result = n1 + n2
# Show result
print("Result:", result)
Output: 👇️
Enter first number: 12
Enter second number: 13
Result: 25
In this example, we take two numbers from the user and show the addition of them.
Adding String Input
We can add string input in Python using the input() function:
# Take user input
name = input("Enter your name: ")
# Show user input
print("Hello " + name + "!")
Output: 👇️
Enter your name: Himani
Hello Himani!
In this example, we take a string from the user and show a message to the user.