芜湖~Python超级超级简易计算器
#原理就是---假设输入8+2后通过for循环把8+2拆成'8' '+' '2'并放到数组里,然后又用for循环来判断是哪一个运算符,后通过数组切片 shuzhu 来取出运算符前和后的数字进行相应运算,最后打印结果print("Python--简易计算器...")
circle=input("在右侧输入一个单次两项计算式子(例如1+2):")
circle_2=[]
for txt in circle:
circle_2.append(txt)
for number in range(len(circle_2)):
if circle_2=="+":
circle_3=circle_2[:number]
circle_4=circle_2
infront=''
behind=''
for number_2 in range(number):
infront=infront+circle_3
for number_2 in range(len(circle_2)-number-1):
behind=behind+circle_4
print(infront+"+"+behind+"="+str(float(infront)+float(behind)))
if circle_2=="-":
circle_3=circle_2[:number]
circle_4=circle_2
infront=''
behind=''
for number_2 in range(number):
infront=infront+circle_3
for number_2 in range(len(circle_2)-number-1):
behind=behind+circle_4
print(infront+"-"+behind+"="+str(float(infront)-float(behind)))
if circle_2=="*":
circle_3=circle_2[:number]
circle_4=circle_2
infront=''
behind=''
for number_2 in range(number):
infront=infront+circle_3
for number_2 in range(len(circle_2)-number-1):
behind=behind+circle_4
print(infront+"*"+behind+"="+str(float(infront)*float(behind)))
if circle_2=="/":
circle_3=circle_2[:number]
circle_4=circle_2
infront=''
behind=''
for number_2 in range(number):
infront=infront+circle_3
for number_2 in range(len(circle_2)-number-1):
behind=behind+circle_4
if behind=="0":
print("除数不能为零...程序即将报错停止")
assert False
print(infront+"/"+behind+"="+str(float(infront)/float(behind)))
页:
[1]