Computer Science, asked by nb0396584, 7 months ago

Write a program that generates two integers under 100 and prompts the user to enter the sum of these two integers. The program then reports true if the answer is correct, false otherwise.

Answers

Answered by poojan
3

Language Used : Python Programming

Important note, DON'T IGNORE : As the original name of the function is being considered as an inappropriate word, I have added another 'a' next to 'r' in the function raandint(). Kindly, Ignore one 'a'.

Note :

Please check the attachment given below to see the interpretation of the program mentioned.

Program :

import random

x=random.raandint(1,100)

y=random.raandint(1,100)

print(x," + ",y," = ?")

print("Enter your answer : ", end="")

z=int(input())

if x+y==z:

   print("True")

else:

   print("False")

Outputs :

Trail 1 : (Entering the right answer)

48  +  52  = ?

Enter your answer : 100

True

Trail 2 : (Entering the wrong answer)

42  +  80  = ?

Enter your answer : 121

False

Explanation :

All we need to do is importing the random library. The random library contains a built-in function raandint() that takes two parameters, ranging elements. It generates the random elements within the range. On displaying those random generated numbers and asking the user to enter their sum, we compare the user inputted value with their actual computed sum. If they matches, the board displays True, else False.

Hope it helps. If yes, leave a smile. :)

Attachments:
Similar questions