Write a program that asks the user for two numbers and store them in two variables called
num1
and num2
. Add them together and store the result in a variable
called result
and print the result back to the user.
NOTE! All input we get from the input function will be stored as strings so num1
and num2
must first be converted to integers with the int()
function.
def main(): num1 = input("Enter the first number: ") num1 = int(num1) #Convert num1 to an integer num2 = input("Enter the second number: ") num2 = int(num2) #Convert num2 to an integer result = num1 + num2 print("The result is", result) if __name__ == '__main__': main()