欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python编程月度总结(小程序)

程序员文章站 2022-05-02 20:27:28
...

一、21点小游戏

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

import random
import string

User_data = {}

def count(User1_sum, User2_sum,User1_name,User2_name):
    "判断用户输入数字的最后结果"
    User1_result = 21 - User1_sum
    User2_result = 21 - User2_sum

    if User1_result < User2_result:
        print(f"恭喜{User1_name}获胜!最后得分为:{User1_sum}")

    elif User2_result < User1_result:
        print(f"恭喜{User2_name}获胜!最后得分为:{User2_sum}")

    elif User1_result == User2_result:
        print(f"{User1_name}和{User2_name}得分都一样,结果为{User1_sum}")

    for k, v in User_data.items():
        print(f"姓名:{k} 总分数:{v}")


def welcome():
    "欢迎+用户输入数字"
    count_str = True
    print("欢迎来到21点小游戏.".center(50,"-"))
    while (count_str):
        User1_name = input("第一个玩家输入姓名:".strip())
        User2_name = input("第二个玩家输入姓名:".strip())

        SystemInt1 = random.randint(1,10)
        SystemInt2 = random.randint(1,10)

        User1_int = int(input(f"请{User1_name}输入一个小于10的数字:".strip()))
        User2_int = int(input(f"请{User2_name}输入一个小于10的数字:".strip()))

        User1_sum = User1_int + SystemInt1
        User2_sum = User2_int + SystemInt2

        User_data[User1_name] = User1_sum
        User_data[User2_name] = User2_sum

        count(User1_sum, User2_sum,User1_name,User2_name)

        print("游戏结束 yes:继续玩 no:退出程序".center(50,"-"))
        result = input("您是否需要继续玩耍?(yes/no):")
        if result == "yes":
            count_str = True

        elif result == "no":
            print("欢迎您再次使用,再见~~~".center(30, "-"))
            count_str = False


def main():
    welcome()

if __name__ == '__main__':
    main()

2、备忘录

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

__author__ = "YanZanG"

from color_me import ColorMe
import sys
import datetime

User_data = {}
User_Ai_data = {}
User_data_list = []


def select():
    "提供用户是否需要重新添加内容"
    select_co = ColorMe(f"您目前已经成功添加{len(User_data_list)}条记录,继续添加:yes 退出:q").blue()
    print(select_co)
    count = True
    while (count):
        input_result = input("请您输入:".strip())
        if input_result == "yes":
            user_input()
        elif input_result == "q":
            print("欢迎您再次使用,再见~")
            count = False
        else:
            warning = ColorMe("警告:请您输入(yes/q)").red()
            print(warning)


def add_database(Date, Event):
    "添加用户输入信息到字典"
    User_data[Date] = Event
    User_data_list.append(User_data)

    data_summary = len(User_data_list)

    print(f"您目前已经成功添加{data_summary}条备忘记录")
    print(f"汇总如下所示".center(50,"="))

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

    select()


def user_input():
    "用户输入事件"
    print("提示 例如:---->记录事件:搞定Python".center(50, "-"))
    count = True
    while (count):
        Date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        Event = input("请您输入您的记录事件:".strip())

        if Event.strip() == "":
            Event_warning = ColorMe("事件不能为空,请您重新输入!!!").red()
            print(Event_warning)
            count = True

        else:
            add_database(Date, Event)
            count = False


def ai_memo():
    "智能识别主程序"
    print("欢迎来到Ai智能识别,例如:hi,延凯明天8点叫我起床".center(50, "-"))

    Ai_count = True
    while (Ai_count):
        User_Ai = input("请您输入一句话表达你想要做什么:".strip())

        if User_Ai.strip() == "":
            Ai_warning = ColorMe("内容不能为空,请您重新输入!!!").red()
            print(Ai_warning)
            Ai_count = True

        else:
            User_Key = User_Ai[User_Ai.find("点")-1] + User_Ai[User_Ai.find("点")]
            User_value = User_Ai[User_Ai.find("点")+1:]
            User_Ai_data[User_Key] = User_value

            print("恭喜您,添加成功,数据如下:".center(50, "-"))

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

            Ai_user_memo = input("您是否还需要添加?(yes/no):")

            if Ai_user_memo == "yes":
                Ai_count = True
            elif Ai_user_memo == "no":
                Ai_count =  False


def menu():
    "提供用户选择菜单内容"
    print(f"欢迎您来到{__author__}备忘录程序.".center(50,"-"))

    User_menu_dict = {
        "1" : "普通备忘录系统",
        "2" : "Ai智能识别备忘录系统",
        "q" : "退出程序"
    }

    print("请您选择..".center(50, "-"))

    # for k, v in User_menu_dict.items():
    #     print(f"{k}、{v}")
    Ai_cou = True

    while (Ai_cou):
        for k, v in User_menu_dict.items():
            print(f"{k}、{v}")
        Your_menu = input("请您输入选项:".strip())

        if Your_menu == "1":
            user_input()
        elif Your_menu == "2":
            ai_memo()
        elif Your_menu == "q":
            print("欢迎您再次使用,再见!!!")
            Ai_cou = False


def main():
    menu()
if __name__ == '__main__':
    main()

3、温度货币转换器

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

__author__ = "YanZanG"

over = False

def Welcome():
    "欢迎词儿~~~"
    print(f"Welcome to the {__author__} program.".center(60, "-"))
    menu_dict = {
        "1" : "货币转换",
        "2" : "温度转换",
        "q" : "退出程序"
    }

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


def currency(User_Input):
    "人民币转换"
    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(User_Input):
    "美元币转换"
    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 temper(User_Input_temp):
    "摄氏温度转华氏温度"
    temper_result = int(User_Input_temp[:User_Input_temp.index("C")])
    Calculation_result = (temper_result * 1.8 + 32)

    print(f"您输入的摄氏度为:{temper_result} ℃ 转换为华氏温度为{Calculation_result}℉" )


def overturn_temper(User_Input_temp):
    "华氏温度转摄氏温度"
    overturn_result = int(User_Input_temp[:User_Input_temp.index("F")])
    Fahrenheit_result = (overturn_result / 1.8 - 32)
    air = round(Fahrenheit_result, 2)

    print(f"您输入的华氏温度为:{overturn_result} ℉ 转换为摄氏温度为{air}℃" )


def input_usr():
    "用户输入金额"
    option = True
    print("Welcome to the yanzan program.".center(60, "-"))

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

        if User_Input.count("元"):
            currency(User_Input)

        elif User_Input.count("$"):
            dollar(User_Input)

        elif User_Input == "q":
            option = over
            print("欢迎您再次使用,再见!!!")

        else:
            print("您只能输入以(元/$)结尾的金额,请您再次检查!!! 提示:(按:q 退出程序)".center(20, "-"))


def temperature():
    "用户输入温度"
    option = True
    while (option):
        User_Input_temp = input("请您输入转换的温度,摄氏温度:( ℃ ) 华氏温度:(℉ ) 退出:(q):".strip())

        if User_Input_temp.count("F"):
            overturn_temper(User_Input_temp)

        elif User_Input_temp.count("C"):
            temper(User_Input_temp)

        elif User_Input_temp == "q":
            option = over
            print("欢迎您再次使用,再见~")

        else:
            print("警告:请您输入,摄氏温度:(C) 华氏温度:(F)结尾! 退出:(q)".center(50,"-"))


def menu_result():
    "用户菜单选择结果"
    option = True
    while (option):
        Welcome()
        Your_select = input("请您输入您需要的业务:".strip())

        if Your_select == "1":
            input_usr()
        elif Your_select == "2":
            temperature()
        elif Your_select == "q":
            print("欢迎您再次使用,再见!")
            option = over
        else:
            print("警告:您只能输入(1/2),如果需要退出请按(q)按钮...".center(50, "-"))


def main():
    menu_result()

if __name__ == '__main__':
    main()

世界万物皆为对象!

Python编程月度总结(小程序)