Ai
1 Star 0 Fork 0

Role/Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SimpleCalculator.py 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
LinjianLi 提交于 2020-10-17 11:31 +08:00 . Change only the format but not the function
#Simple Calculator
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
try:
return a / b
except ZeroDivisionError:
return "Zero Division Error"
def power(a,b):
return a**b
def main():
print("Select Operation")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Power")
choice = input("Enter Choice(+,-,*,/,^): ")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter Second number:"))
if choice == '+':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '-':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '*':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '/':
print(num1, "/", num2, "=", divide(num1, num2))
elif choice =="**":
print(num1,"^",num2,"=",power(num1,num2))
else:
print("Invalid input")
main()
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CRole/Python.git
git@gitee.com:CRole/Python.git
CRole
Python
Python
master

搜索帮助