w3resource

Python: Compute and print sum of two given integers

Python Basic - 1: Exercise-41 with Solution

Write a Python program to compute and print the sum of two given integers (greater or equal to zero). In the event that the given integers or the sum exceed 80 digits, print "overflow".

Sample Solution:

Python Code:

print("Input first integer:")
x = int(input())
print("Input second integer:")
y = int(input())
if x >= 10 ** 80 or y >= 10 ** 80 or x + y >= 10 ** 80:
    print("Overflow!")
else:
    print("Sum of the two integers: ",x + y)

Sample Output:

Input first integer:
 25
Input second integer:
 22
Sum of the two integers:  47

Flowchart:

Flowchart: Python - Compute and print sum of two given integers

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check if a point (x,y) is in a triangle or not. There is a triangle formed by three points.
Next: Write a Python program that accepts six numbers as input and sorts them in descending order.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.