猫史档案馆


【Python作品分享】calculator【作品秀】

用户:米米兔时光机米米兔时光机查看:0 回复:0 评论:0 创建时间:2021-12-05T16:07:22


【作品展示】

center_image

 

【作品介绍】

calculator

 

【作品源代码】

#! Python 3
# Old stubs for the calculator (PyCharm 2020.2 | Python 3.7.0)
# New stubs for the calculator (海龟编辑器 V1.7.2x喵 | Python 3.9.7)
# This is my 1st module
# Version 0.2021.12.5.12.15.55
# V.0.2021.12.5.15.55
# Code by Kingsley [From China]
# Updated by Kingsley [From China]
# The language is English and Chinese
# Thanks for use
# ---------- calculator ----------

import time

def calculator():

    print('Welcome use the calculator!')
    while True:
        try:
            print('1.Plus; 2.Minus; 3.Multiply; 4.Divide; 5.Power; 6.Quit...\n')
            a = input()
            if a == '1':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a + b
                    print(c)
                except ValueError:
                    print(f'''
Please inter numbers.
The error are in you -:
    Inter of error: You - is not numbers.
                                ''')
            elif a == '2':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a - b
                    print(c)
                except ValueError:
                    print(f'''
Please inter numbers.
The error are in you -:
    Inter of error: You - is not numbers.
                                ''')
            elif a == '3':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a * b
                    print(c)
                except ValueError:
                    print(f'''
Please inter numbers.
The error are in you -:
    Inter of error: You - is not numbers.
                                ''')
            elif a == '4':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a / b
                    print(c)
                except ValueError:
                    print(f'''
Please inter numbers.
The error are in you -:
    Inter of error: You - is not numbers.
                                ''')
            elif a == '5':
                try:
                    a, b = float(input('Please inter by power number.')), int(input('Please inter number of power.'))
                    c = a ** b
                    print(c)
                except ValueError:
                    print(f'''
Please inter numbers.
The error are in you -:
    Inter of error: You - is not numbers.
                                ''')
            elif a == '6':
                break
            else:
                print(f'''
Please inter numbers 1 ~ 6.
Traceback (most recent error) in you -:
    Inter of error: '{a}' is not 1 ~ 6.
                            ''')
        except ZeroDivisionError:
            print('''
Please do not divide by '0'.
The error are in your -; -:
    Division of error: Divide by '0'.
                        ''')
        else:
            pass
        finally:
            pass
    exit()


if __name__ == '__main__':
    print('Welcome you, admin!')
    while True:
        print('Do you want look the code?(Y/n)')
        admin = input()
        if admin == 'Y' or 'y' or 'yes' or 'Yes':
            print('''
#! Python 3
# Old stubs for the calculator (PyCharm 2020.2 | Python 3.7.0)
# New stubs for the calculator (海龟编辑器 V1.7.2x喵 | Python 3.8.5)
# This is my 1st module
# Version 0.2021.12.5.12.15.30
# V.0.2021.12.5.15.30
# Code by Kingsley [From China]
# Updated by Kingsley [From China]
# The language is English and Chinese
# Thanks for use
# ---------- calculator ----------

import time

def calculator():

    while True:
        try:
            print('1.Plus; 2.Minus; 3.Multiply; 4.Divide; 5.Power; 6.Quit...\n')
            a = input()
            if a == '1':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a + b
                    print(c)
                except ValueError:
                    print(f\'\'\'
                  Please inter numbers.
                  The error are in you -  :
                  Inter of error: You -  is not numbers.
                  \'\'\')
            elif a == '2':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a - b
                    print(c)
                except ValueError:
                    print(f\'\'\'
                  Please inter numbers.
                  The error are in you -  :
                  Inter of error: You -  is not numbers.
                  \'\'\')
            elif a == '3':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a * b
                    print(c)
                except ValueError:
                    print(f\'\'\'
                  Please inter numbers.
                  The error are in you -  :
                  Inter of error: You -  is not numbers.
                  \'\'\')
            elif a == '4':
                try:
                    a, b = float(input('Please inter 1st number.')), float(input('Please inter 2nd number.'))
                    c = a / b
                    print(c)
                except ValueError:
                    print(f\'\'\'
                  Please inter numbers.
                  The error are in you -  :
                  Inter of error: You -  is not numbers.
                  \'\'\')
            elif a == '5':
                try:
                    a, b = float(input('Please inter by power number.')), int(input('Please inter number of power.'))
                    c = a ** b
                    print(c)
                except ValueError:
                    print(f\'\'\'
                  Please inter numbers.
                  The error are in you -  :
                  Inter of error: You -  is not numbers.
                  \'\'\')
            elif a == '6':
                break
            else:
                print(f\'\'\'
                  Please inter numbers 1 ~ 6.
                  Traceback (most recent error) in you -  :
                  Inter of error: '{a}' is not 1 ~ 6.
                  \'\'\')
        except ZeroDivisionError:
            print(\'\'\'
                  Please do not divide by '0'.
                  The error are in your -  ; - < divide > :
                  Division of error: Divide by '0'.
                  \'\'\')
        else:
            pass
        finally:
            pass
    exit()


if __name__ == '__main__':
    print('Welcome you, admin!')
    while True:
        print('Do you want look the code?(Y/n)')
        admin = input()
        if admin == 'Y' or 'y' or 'yes' or 'Yes':
            print('''
                "this code"
                  ''')
        time.sleep(10)
        elif admin == 'N' or 'n' or 'no' or 'No':
            pass
        break
    calculator()
else:
    calculator()

            ''')
        time.sleep(10)
        break
    calculator()
else:
    calculator()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页