How to add numbers in Python 3

Write a program that adds the digits in a 2 digit number. e.g. if the input was 35, then the output should be 3 + 5 = 8

Solution:

digits = input("Input 2 digit number: ")
num_1 = digits[0]
num_2 = digits[1]
output = int(num_1) + int(num_2)
print(f"Output is {num_1} + {num_2} = {output}")

Leave a Comment