Ask Question
25 November, 11:29

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.

+3
Answers (1)
  1. 25 November, 11: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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers