<分区> 分区>
我当时正在用 Python 开发一个项目,其中涉及随机选择一个运算符(乘法、除法、加法和减法),然后对两个整数执行该运算。到目前为止,我的代码将以字符的形式随机选择运算符。我正在苦苦挣扎的实际上是在做数学。这是我的代码:
from random import randint
inputA = 2
inputB = 3
output = 0
desiredOutput = 5;
#possible operations: addition, subtraction, multiplication, division
add = "+"
multiply = "*"
divide = "/"
subtract = "-"
#choose randomely between the four
chooser = randint(1,4)
chosen = add
if chooser == 1:
chosen = add
if chooser == 2:
chosen = multiply
if chooser == 3:
chosen = divide
if chooser == 4:
chosen = subtract
现在我要做的是从输入 B 中获取输入 A 并分别对其进行乘法、除法、加法或减法(使用“选择的”运算符)。
谢谢,阿维德
