ETO. 发表于 2023-7-14 14:38:21

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()

三春牛-创客 发表于 2023-7-15 22:17:26

不错不错

三春牛-创客 发表于 2023-7-15 22:20:24

刚好在学Python,感谢分享!

花生编程 发表于 2023-7-16 21:57:48

赞赞赞赞赞

花生编程 发表于 2023-7-16 22:02:56

函数,不错
页: [1]
查看完整版本: Mind+计算器