Create an interactive program that takes in two integers and outputs their sum.
In this exercise, you have to create a program that asks the user to input two integers, one-by-one, and then outputs their sum.
The first input prompt of the program should be of the form shown below:
<input> denotes the input of the user.
Similarly, the second input should be of the form:
The output should be:
The sum is: <sum>
<sum> is the sum of the input integers.
Shown below is an example:
Inside the directory you created for this course on Python, create a new folder called Exercise-1-Addition-Calculator and put the .py solution files for this exercise within it.
As instructed in the question, first we need to ask the user to input a value for
x and then a value for
y, with the prompts
'x: ' and
'y: ', respectively.
x = input('x: ') y = input('y: ')
b, but since the prompt messages specifically use the names
'y', it would be straightforward to go with these names for the variables as well.
Next, up we need to convert both
y to integers using the function
x = input('x: ') y = input('y: ') # convert x to int x = int(x) # convert y to int y = int(y)
Finally, we just ought to add
y together and print out the result, as desired in the exercise.
x = input('x: ') y = input('y: ') # convert x to int x = int(x) # convert y to int y = int(y) print('The sum is:', x + y)
Below, we use this program to add two numbers: