写一段10以内加减法代码
这段代码可以让用户输入两个数字,然后进行加法或减法运算,最后输出结果。
num1 = int(input("请输入第一个数字:"))
num2 = int(input("请输入第二个数字:"))
operator = input("请选择运算符(+或-):")
if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
else:
print("无效的运算符")
print("结果是:", result)
原文地址: https://www.cveoy.top/t/topic/fidn 著作权归作者所有。请勿转载和采集!