import random
# main function
def main():
print("This program prints 2 random numbers between 1 and 2000 and asks you to add them.")
print("Type the answer after you see the 2 random numbers.")
#generate 2 different numbers to add together
num1 = random.randint(1,2000)
num2 = random.randint(1,2000)
# print and add the two integers
# correct answer to equation
total = sum(num1, num2)
# print the equation on 3 lines
print(num1, \n, "+",\n, num2))
# asking for the user to input answer
answer = int(input("Enter answer to math problem: "))
# if statement
if total == answer:
print("You are correct!")
else:
print("Try again." \n, "Correct answer is: " \n, format(num3, '.2f'))
# defining the addition function
def sum(num1, num2):
return num1 + num2
# call main function
main()

Tweet This+ 1 thisPost To Linkedin