您可以使用字典执行此操作:
operators = { 1: "+", 2: "-", 3: "/", 4: "*" } operators = operator[z] // where z is the random integer for gettig the operator.
在你的书面声明中
print("What is " + str(x)+" " + str(operator)+" " + str(y)+"?")