Mind+计算器

2023-07-141.4万
AI 快速预览详细 收起
本文介绍了如何使用Mind+编写一个简单的计算器程序,支持加、减、乘、除四种基本运算。通过输入选项,用户可以选择不同的运算类型,并输入数值进行计算。这个项目非常适合编程初学者,特别是儿童和青少年,帮助他们在实践中学习编程基础知识。
def hello():
    print('欢迎使用本计算器!')
    while True:
        select = int(input('请输入要操作的选项:1加法 2减法 3乘法 4除法'))
        if select == 1:
            add()
        elif select == 2:
            red()
        elif select == 3:
            rid()
        elif select == 4:
            exc()
        else:
            print('你的输入有误,请重新输入!!!')
            continue
        choice = input('是否继续?继续输入y,输入任意键退出.')
        if choice != 'y':
            break


def add():
    a = float(input('请输入第一个加数:'))
    b = float(input('请输入第二个加数:'))
    result = a + b
    print('两个数的和为{}'.format(result))


def red():
    a = float(input('请输入被减数:'))
    b = float(input('请输入减数:'))
    result = a - b
    print('两个数的差为{}'.format(result))


def rid():
    a = float(input('请输入第一个因数:'))
    b = float(input('请输入第二个因数:'))
    result = a * b
    print('两个数的积为{}'.format(result))


def exc():
    a = float(input('请输入被除数:'))
    b = float(input('请输入除数:'))
    result = a / b
    print('两个数的商为{}'.format(result))


hello()

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(4)
花生编程
花生编程
函数,不错
花生编程
花生编程
赞赞赞赞赞
三春牛-创客
三春牛-创客
刚好在学Python,感谢分享!
三春牛-创客
三春牛-创客
不错不错
- 没有更多了 -