Ask Question
12 March, 03:04

4. Write a program which selects two integer numbers randomly, adds the numbers and asks the user to enter the answer and then checks if the answer is correct or not.

+4
Answers (1)
  1. 12 March, 05:43
    0
    import random

    number1 = random. randrange (0, 1000)

    number2 = random. randrange (0, 1000)

    answer = int (input ("Enter a number: "))

    if answer = = number1 + number2:

    print ("Your answer is correct")

    else:

    print ("Your answer is not correct")

    Explanation:

    The code is in Python

    Create two integer numbers using random

    Ask the user for an input

    Check if answer is equal to number1 + number2. If they are equal, print "answer is correct". Otherwise, print "answer is not correct".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “4. Write a program which selects two integer numbers randomly, adds the numbers and asks the user to enter the answer and then checks if ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers