计算器功能:两个整数的加减乘除。刚刚开始学所以功能很简单。
#设计一个计算器,用于两个数的加减乘除,并显示结果
#要用到easygui实现界面交互
#设计一个计算器,用于两个数的加减乘除,并显示结果
#要用到easygui实现界面交互
import easygui as sc
title = "Simple_Calculator"
end_sign = 1#结束判断标志
result = 0#默认结果为0
sc.msgbox(msg='欢迎使用', title=title, image='calculator.gif', ok_button='开始')
# 欢迎界面 文件夹中要有calculator.gif命名的图片
while end_sign:
first_number = sc.integerbox(msg='输入第一个数', title=title,lowerbound=-999999, upperbound=999999)
if first_number is None:#判断要不要继续
break
operation = sc.buttonbox(msg='选择运算符号', title=title, choices=['+', '-', '*', '/'])
if operation is None:#判断要不要继续
break
second_number = sc.integerbox(msg='输入第二个数', title=title,lowerbound=-999999, upperbound=999999)
if second_number is None:#判断要不要继续
break
if operation == '+':
result = first_number + second_number
if operation == '-':
result = first_number - second_number
if operation == '*':
result = first_number * second_number
if operation == '/':
result = first_number / second_number
result = "计算结果:"+str(first_number)+operation+str(second_number)+'='+str(result) #运算过程
end_sign = sc.indexbox(msg=result, title=title, choices=['结束','继续'] )
# 显示计算过程和结果结果,并判断要不要继续,点”结束“ end_sign赋值为0,退出程序。