Feb-02-2021, 02:56 PM
Hi,
I have the following code:
I would like to keep the structure of the code and keep it at a minimum to accomplish the following:
e.g. random operation is '-'
it should print 10 - 5 = ?
I have the following code:
import random number_one = random.randint(0, 100) number_two = random.randint(0, 100) rand_ops = ['+', '-', '/', '*'] while(True): correct_answer = eval (str(number_one) + random.choice(rand_ops) + str(number_two)) trial = input('What is the correct answer for:'+ str(number_one) +random.choice(rand_ops)+ str(number_two)+'=' ) if int(trial) != int(correct_answer): print('That is incorrect. Try again. :(') continue else: print('That is correct. Great job!'':)') breakThis code does not recognize the correct answer.
I would like to keep the structure of the code and keep it at a minimum to accomplish the following:
- Generate two random numbers between 0 and 100
- Generate a random operation ( +, -, /, * , ** )
- Generate a random operation ( +, -, /, * , ** )
e.g. random operation is '-'
it should print 10 - 5 = ?
- Get the input from the user
- Validate the answer
- Validate the answer