Python小程序 货币转换 v2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39591494/article/details/82315570
#!/usr/bin/env python
# -*- coding:utf-8 -*-

__author__ = "YanZanG"

over = False

from color_me import ColorMe


class Info(object):
    def __init__(self, name, age, wages, Sex, phone):
        self.name = name
        self.age = age
        self.wages = wages
        self.Sex = Sex
        self.phone = phone

    def info(self):
        print("恭喜您,通过认证,您的基本信息如下:".center(50,"="))
        print(f"""
        姓名:{self.name}
        年龄:{self.age}
        工资:{self.wages}
        性别:{self.Sex}
        电话:{self.phone}
        """)


class Money(object):
    """货币转换系统"""
    def rmb(self):
        """人民币转换美元..."""
        option = True

        while (option):
            User_Input = input("请您输入您需要转换的金额,人民币:(元) 退出:Q :".strip())


            if User_Input.strip() == "":
                User_Input_warning = ColorMe("警告:输入的金额不能为空,请您重新输入!!!").red()
                print(User_Input_warning)

            elif User_Input == "q":
                User_Input_q = ColorMe("警告:检测输入q为小写,请您重新输入!!!").red()
                print(User_Input_q)

            elif User_Input == "Q":
                print("欢迎您再次使用人民币转换工具,再见~".center(50, "-"))
                option = over

            elif User_Input.endswith("元") == False:
                User_Input_end = ColorMe("警告:输入的人民币以'元'结尾,请您重新输入!!!").red()
                print(User_Input_end)

            else:
                your_money = int(User_Input[:User_Input.index("元")])

                rmb = your_money / 6.6
                rmb = round(rmb, 2)

                Conversion_results = (f"您需要转换的人民币为{User_Input} 转换为美元结果为:{rmb}$(按Q退出!!!)")
                print(Conversion_results)


    def dollar(self):
        """美元转换人民币..."""
        option = True

        while (option):
            User_Input = input("请您输入您需要转换的金额,美元:($) 退出:Q:".strip())
            if User_Input.strip() == "":
                User_Input_warning = ColorMe("警告:输入的金额不能为空,请您重新输入!!!").red()
                print(User_Input_warning)

            elif User_Input == "q":
                User_Input_q = ColorMe("警告:检测输入q为小写,请您重新输入!!!").red()
                print(User_Input_q)

            elif User_Input == "Q":
                print("欢迎您再次使用美元转换工具,再见~".center(50, "-"))
                option = over

            elif User_Input.endswith("$") == False:

                User_Input_end = ColorMe("警告:输入的美元以'$'结尾,请您重新输入!!!").red()
                print(User_Input_end)

            else:
                your_money = int(User_Input[:User_Input.index("$")])
                rmb = your_money * 6.6
                rmb = round(rmb, 2)
                Conversion_results = (f"您需要转换的美元为{User_Input} 转换为人民币结果为:{rmb}$(按Q退出!!!)")
                print(Conversion_results)


class Transfer(Info,Money):
    def __init__(self, name, age, wages, Sex, phone, height):
        Info.__init__(self, name, age, wages, Sex, phone)
        Money.__init__(self)
        self.height = height

    def name_info(self):
        return  result.info()

    def user_input(self):
        Really = True
        while (Really):
            menu_dict = {
                "1" : "人民币转美元程序",
                "2" : "美元转人民币程序",
                "Q" : "退出此程序"
            }

            for k, v in menu_dict.items():
                print(f"{k}、{v}")

            user_result = input("请您选择你需要的业务:".strip())
            if user_result == "1":
                self.rmb()
            elif user_result == "2":
                self.dollar()
            elif user_result == "Q":
                print("欢迎您再次使用,再见!".center(50,"-"))
                Really = False
            else:
                print("请您输入(1/2/Q)")

def User_info():
    OB = True
    while (OB):
        print(f"欢迎来到{__author__}翻译小程序,我们需要进一步了解您的信息!!!".center(50,"-"))
        Your_name = input("请您输入您的名字:".strip())
        Your_age = input("请您输入您的年龄:".strip())
        Your_wages = input("请您输入您的工资:".strip())
        Your_Sex = input("请您输入您的性别:".strip())
        Your_phone = input("请您输入您的电话:".strip())
        Your_height = input("请您输入您的身高:".strip())

        if Your_name.strip() == "":
            User_Input_n = ColorMe("警告:姓名不能为空,请您重新输入!!!").red()
            print(User_Input_n)
        elif Your_age.strip() == "":
            User_Input_a = ColorMe("警告:年龄不能为空,请您重新输入!!!").red()
            print(User_Input_a)
        elif Your_wages.strip() == "":
            User_Input_w = ColorMe("警告:工资不能为空,请您重新输入!!!").red()
            print(User_Input_w)
        elif Your_Sex.strip() == "":
            User_Input_s = ColorMe("警告:性别不能为空,请您重新输入!!!").red()
            print(User_Input_s)
        elif Your_phone.strip() == "":
            User_Input_p = ColorMe("警告:电话不能为空,请您重新输入!!!").red()
            print(User_Input_s)
        elif Your_height.strip() == "":
            User_Input_h = ColorMe("警告:身高不能为空,请您重新输入!!!").red()
            print(User_Input_h)
        else:
            result = Transfer(Your_name, Your_age, Your_wages, Your_Sex, Your_phone,Your_height)
            result.info()
            result.user_input()
            OB = False
User_info()


ColorMe.py

#!/usr/bin/env Python
#-*- coding:utf-8 -*-

__author__ = 'De8ug'

class ColorMe:
    """
    give me color see see...
    实际用起来很简单:
        ColorMe('somestr').blue()
    """
    def __init__(self, some_str):
        self.color_str = some_str

    def blue(self):
        str_list = ["\033[34;1m", self.color_str, "\033[0m"]
        return ''.join(str_list) # "\033[34;1m" + self.color_str + "\033[0m"

    def green(self):
        str_list = ["\033[32;1m", self.color_str, "\033[0m"]
        return ''.join(str_list) # "\033[34;1m" + self.color_str + "\033[0m"

    def yellow(self):
        str_list = ["\033[33;1m", self.color_str, "\033[0m"]
        return ''.join(str_list) # "\033[34;1m" + self.color_str + "\033[0m"

    def red(self):
        str_list = ["\033[31;1m", self.color_str, "\033[0m"]
        return ''.join(str_list) # "\033[34;1m" + self.color_str + "\033[0m"


def main():
    ColorMe('somestr').blue()

if __name__ == '__main__':
    main()

猜你喜欢

转载自blog.csdn.net/qq_39591494/article/details/82315570