pathon模拟计算器

n1=float(input("请输入第一个参数"))
n2=float(input("请输入第二个参数"))
#input输入默认的是字符串,所以需要进行类型转换;
c=int(input("请输入你要进行的操作选项1求和2,求差3 求积4 求商 5取余6取整"))
if c==1 :
    print("结果是:%.2f" % (n1 + n2))
elif c==2 :
    print("结果是:%.2f" % (n1 - n2))
elif c==3 :
    print("结果是:%.2f" % (n1 * n2))
elif c==4 :
    print("结果是:%.2f" % (n1 / n2))
elif c==5 :
    print("结果是:%.2f" % (n1 % n2))
elif c==6 :
    print("结果是:%.2f" % (n1 // n2))
print("end")

The second option

while True:
    n1 = float(input("输入数1    "))
    n2 = float(input("输入数2    "))
    c = input("请选择您要执行的操作加/减/乘/除/取余/q")
    if c == "加":
        c2=n1+n2
        print(c2)

    elif c == "减":
        c2 = n1 - n2
        print(c2)
    elif c == "乘":
        c2 = n1 * n2
        print(c2)
    elif c == "除":
        c2 = n1 / n2
        print(c2)
    elif c == "取余":
        c2 = n1 % n2
        print(c2)
    elif  c == "q":
        print("您已选择停止运行计算机")
        break

你可能感兴趣的:(前端,服务器,javascript)