我今天学了python,一知半解,自己写了这个程序
但是运行全错误,不知道为什么,求解答!
# -*- coding: UTF-8 -*-
import time
import sys
print("你好,这是foromer编写的Math_bot")
time.sleep(2)
print("你将要进行数学运算吗?")
time.sleep(2)
y = "是"
n = "否"
a=input("是否继续:") #用于回答上方问题
if a == y:
print("那我们继续吧")
time.sleep(1)
elif a == n:
print("那就将结束了")
time.sleep(2)
sys.exit()
print("Math_bot包含五种运算,分别是:")
time.sleep(1.5)
print("加法")
time.sleep(0.5)
print("减法")
time.sleep(0.5)
print("乘法")
time.sleep(0.5)
print("除法")
time.sleep(0.5)
print("乘方")#告知运算
time.sleep(2)
choice = input("请选择运算:")#输入运算的选择
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
def pow(x,y):
return pow(x,y)
if choice == "加法":
Num1 = input("请输入第一个加数:")
time.sleep(1)
Num2 = input("请输入第二个加数:")
print(Num1,"+",Num2,"=", add(Num1,Num2))
elif choice == "减法":
Num1 = input("请输入被减数:")
time.sleep(1)
Num2 = input("请输入减数:")
print(Num1,"-",Num2,"=", subtract(Num1,Num2))
elif choice == "乘法":
Num1 = input("请输入第一个乘数:")
time.sleep(1)
Num2 = input("请输入第二个乘数:")
print(Num1,"*",Num2,"=", multiply(Num1,Num2))
elif choice == "除法":
Num1 = input("请输入被除数:")
time.sleep(1)
Num2 = input("请输入除数:")
print(Num1,"/",Num2,"=", divide(Num1,Num2))
elif choice == "乘法":
Num1 = input("请输入底数:")
time.sleep(1)
Num2 = input("请输入指数:")
print(Num1,"^",Num2,"=", pow(Num1,Num2))
time.sleep(2)
print("感谢用户的支持,我们已成功进行了一次数学运算")