NumGenerator
- Lim Long Teck
- Jun 24, 2021
- 1 min read
Write a program that generates two integers between 0 and 100 inclusive and prompts the user to enter the sum of these 2 integers. The program reports if the answer is correct or wrong (program will also print the correct answer if the user answer is wrong).
Program:
import random
num1 = random.randint(0,100)
num2 = random.randint(0,100)
sum = num1+num2
ans = int(input('Enter the sum of {} and {}: '.format(num1,num2)))
if sum == ans:
print('Your answer is correct!')
else:
print('Your answer is wrong.')
print('The correct asnwer is {}.'.format(sum))
Output:
Enter the sum of 72 and 12: 84
Your answer is correct!
---------------------or---------------------
Enter the sum of 72 and 12: 89
Your answer is wrong.
The correct answer is 84.
Comments