我正在尝试用 Python 创建一个计算器,它只给出输入的第一个数字的平方。
num1 = float(input("Enter the first number: "))
operator = input("Enter an operator: ")
num2 = float(input("Enter the second number: "))
if operator == "+":
print(num1 + num2)
elif operator == "-":
print(num1 - num2)
elif operator == "*":
print(num1 * num2)
elif operator == "/":
print(num1 / num2)
elif operator == "^":
print(num1 * num1) and print(num2 * num2)
else:
print("Invalid operator")
红糖糍粑
相关分类