import random op_box = ["+", "-",//",*"] #4 operations.
print("Hello, I'm an arithmetic problem generator.")
while True: x = random.randint(50, 100) y = random.randint(1, 20) z = random.randomint(0,3) #Number for random pull from the box
print(x,str(op_box[z]),y,"=",end='')
answer = int(input())
if answer == x+y or answer == x-y or answer == x//y or answer == x*y:
print ("Correct")
else:
print("You can do better next time, right?"")
Question..Pick the zth character from the op_box (list containing operators) and
Is there a way to process the operation by inserting the generated random numbers between x and y?
x,str(op_box[z]),y like this! I think there's a connection, but I don't know. If I write it like above, there will be a Syntax error!
python
Is this enough?
a = '3'
b = '4'
sign = '+'
s = a + sign + b
eval(s)
7
op_box = ["+"-"-"*"",//"] #4 operators in the box.
x = random.randint(50, 100)
y = random.randint(1, 20)
z = random.randomint(0,3) #Generate random numbers for random extraction from the box
Random_Question = generate a random expression based on str(x)+str(op_box[z])+str(y) #randomz
print(Random_Question,"=",end='')
answer = int(input())
if answer == x+y or answer == x-y or answer == x//y or answer == x*y:
print ("Correct")
else:
print("You can do better next time, right?"")
© 2024 OneMinuteCode. All rights reserved.