x= int(input("Please enter the value of x: "))
y= int(input("Please enter the value of y: "))
operator = input("Please enter an operator you would like to complete the equation:")
if operator > '*':
print("The result of the equation is: ", x*y)
elif operator > '+':
print("The result of the equation is ", x+y)
elif operator > '-':
print("The result of the equation is", x-y)
elif operator > '/':
print("The result of the equation is ", x/y)
使用我的代码块,我试图将它带到操作员用户输入的位置,并根据他们输入的内容完成数学方程式,目前当我运行它时,它只会使用乘法。
答案 0 :(得分:1)
您正在使用'>'检查平等操作员。在python'>'用于检查大于船舶的关系。检查平等使用' =='操作
if operator == '*':
print("The result of the equation is: ", x*y)
elif operator == '+':
print("The result of the equation is ", x+y)
elif operator == '-':
print("The result of the equation is", x-y)
elif operator == '/':
print("The result of the equation is ", x/y)