马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 excellian 于 2021-3-28 12:14 编辑
刚开始学Python,编了一个极简单的计算器,还请各位大神多多指导鸭🦆~
(该代码不需要使用Pygame)
有建议的可以跟帖哦~print('使用说明:首先输入第一个数字\n 根据提示输入运算符号\n 输入第二个数字\n 按回车键出答案\n 进行第二次计算可直接输入第一个数字\n 通过回车键进入下一步\n 请使用英语输入法\n 若要结束计算,在完成上一次计算后输入“over”\n 该程序暂不支持除整数以外的其他数字ˉ\_(ツ)_/ˉ')
while 1 < 2:
a = input()
if a == "over":
break
print('请输入:+ - * / ** !')
algorithm = input()
if algorithm == "+":
b = input()
def addition(a,b):
sum = int(a) + int(b)
print(sum)
addition(a,b)
if algorithm == "-":
b = input()
def subtraction(a,b):
difference = int(a) - int(b)
print(difference)
subtraction(a,b)
if algorithm == "*":
b = input()
def multiplication(a,b):
product = int(a) * int(b)
print(product)
multiplication(a,b)
if algorithm == "/":
b = input()
def division(a,b):
quotient = int(a) / int(b)
print(quotient)
division(a,b)
if algorithm == "**":
b = input()
def involution(a,b):
answer1 = int(a) ** int(b)
print(answer1)
involution(a,b)
if algorithm == "!":
def factorial(a):
answer2 = 1
if int(a) % 1 == 0:
if int(a) == 0:
print(answer2)
while int(a) > 0:
answer2 = answer2 * int(a)
a = int(a) - 1
if int(a) == 0:
print(answer2)
if int(a) < 0:
print('wrong')
factorial(a)
|