194k views
4 votes
Sum.Write a program that prompts the user to read two integers and displays their sum.Your program should prompt the user to read the number again if the input is incorrect.

User Daniel Kua
by
4.6k points

1 Answer

3 votes

Answer:

while True:

number1 = input("Enter the number1: ")

number2 = input("Enter the number2: ")

if number1.isnumeric() and number2.isnumeric():

break

number1 = int(number1)

number2 = int(number2)

print("The sum is: " + str(number1 + number2))

Step-by-step explanation:

*The code is in Python.

Create an infinite while loop. Inside the loop, Get the number1 and number2 from the user. Check if they are both numeric values. If they are, stop the loop (Otherwise, the program keeps asking for the numbers).

When the loop is done, convert the numbers to integer numbers

Calculate and print their sum

User George Rushby
by
4.6k points