114k views
0 votes
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.

User Suziki
by
6.7k points

1 Answer

2 votes

Answer:

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")

Step-by-step 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".

User Elad Benda
by
7.5k points