Write a Python program to find the addition of given two numbers num1 and num2 by user input.
Example :
Input:
Enter the first number: 20
Enter the second number: 30
Output: 50
In python input() method is used to take input from user or you can say take input from user prompt. and best thing about this input() method is that you don't have to write input message to other print function before like we do in other programming languages.
print("Enter the first number:")
num1 = input()
in short, you can write in one line
num1 = input("Enter the first number:")
Both the way is good. you can choose any one. second one is most preferable
return type of input() method in python is string and there is no separate method for int, float or string input. so when ever we need any data type other than string then we will have to convert input into desired data type like int, float or bool
Here is complete program in python to add two numbers:
# Python3 program to add two numbers
number1 = input("Enter the first number: ")
number2 = input("Enter the Second number: ")
# Adding two numbers
# User might also enter float numbers
sum_of_two_numbers = int(number1) + int(number2)
# Display the sum
# will print value in float
print("The sum of {0} and {1} is {2}" .format(number1, number2, sum_of_two_numbers))
Output:
Enter the first number: 20
Enter the Second number: 30
The sum of 20 and 30 is 50