我花了1小时做的计算器
main.py代码from MyAlgorithmPackage.MyCalculator import MyOperator
# import MyCalculatorProject.operator as operator
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
while True:
'''
Add 加 +
ReductionOf 减 -
Take 乘 *
InAdditionTo 除 /
Aliquot 整除 //
ForMoreThan 求余 %
'''
if InputOperator == '+':
MyOperator.Add(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
elif InputOperator == '-':
MyOperator.ReductionOf(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
elif InputOperator == '*':
MyOperator.Take(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
elif InputOperator == '/':
MyOperator.InAdditionTo(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
elif InputOperator == '//':
MyOperator.Aliquot(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
elif InputOperator == '%':
MyOperator.ForMoreThan(InputNumberOne, InputNumberTwo)
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
else:
print('输入有误,请重新输入。')
IpublicBoolKeepRunning = str(input('是否继续(y/n):'))
if IpublicBoolKeepRunning == 'y':
InputNumberOne = int(input('请输入第一个数字:'))
InputOperator = str(input('输入运算符(+ - * / // %):'))
InputNumberTwo = int(input('请输入第二个数字:'))
else:
exit()
MyOperator.py代码
def Add(NumberOne, NumberTwo):
print(NumberOne + NumberTwo)
def ReductionOf(NumberOne, NumberTwo):
print(NumberOne - NumberTwo)
def Take(NumberOne, NumberTwo):
print(NumberOne * NumberTwo)
def InAdditionTo(NumberOne, NumberTwo):
print(NumberOne / NumberTwo)
def Aliquot(NumberOne, NumberTwo):
print(NumberOne // NumberTwo)
def ForMoreThan(NumberOne, NumberTwo):
print(NumberOne % NumberTwo)
牛逼!
我的方向是图形界面……
我做的(第一版):https://fishc.com.cn/thread-145507-1-1.html
我做的(第二版):https://fishc.com.cn/thread-145510-1-1.html
页:
[1]