猜年龄游戏plus版

第一次独立写了这么大一坨代码,虽然有些地方没想起来参考了一下,但大部分还是我自己写的好吧,至少不来个6成?(函数学完应该能改进出来个pro),但目前我还是很满意的
咱就是说,拿下拿下!^--^

import os
import subprocess
#注册
register_choice = input("是否需要注册,需要输入y!")

if register_choice == "y":
    print("注册".center(100,'*'))
    username = input("请输入你的用户名:\n")
    password = input("请输入你的密码:\n")
    with open(r'users information.txt','a',encoding='utf-8') as fa:
        fa.write(f'{username}:{password}\n')

while True:
    #登录
    print("登录".center(100,'*'))
    username_login = input("请输入您的用户名:")
    password_login = input("请输入您的密码:")
    user_dict = dict()

    #打开文件拿到用户信息并处理
    with open(r'users information.txt','r',encoding='utf-8') as fr:
        for user in fr:
            user_list = user.strip().split(':')
            user_dict[user_list[0]] = user_list[1]
    #验证信息是否正确
    if username_login in user_dict and password_login == user_dict.get(username_login):
        print("登陆成功!")
        break
    elif username_login in user_dict and password_login != user_dict.get(username_login):
        print("您的密码错误,请重新输入!")
        continue
    elif username_login not in user_dict:
        print("您的账号不存在,请先注册账号!")
        subprocess.run(['python', '猜年龄游戏plus.py'], check=True)  #重启当前程序,询问是否注册

age = 18
count = 3

# 游戏
while count:

    # 判断输入的年龄是否有问题
    while 1:
        age_input = input("请输入你要猜的年龄》》》").strip()
        if age_input.isdigit():
            break
        else:
            print("傻逼,一个年龄都输入不明白吗?")

    age_int = int(age_input)
    if age_int == age:
        print("猜对了!")

        #猜对了,选奖品
        prize_dict = {0:"lol",
                      1:"cf",
                      2:"yuanshen",
                      3:"bilibili"}
        print(f"请输入你想选择的奖品,你可以选择两个:{prize_dict}")

        prize_choice_dict = dict()
        for i in range(2):
            prize_choice = int(input(f"请选择你的第{i+1}奖品:"))
            if prize_dict[prize_choice] not in prize_choice_dict:
                prize_choice_dict[prize_dict[prize_choice]] = 1
            else:
                prize_choice_dict[prize_dict[prize_choice]] += 1
        print(f"恭喜你获得奖品  {prize_choice_dict}  !")
        break


    elif age_input > age:
        print('猜大了,傻逼!')
    else:
        print("傻逼,猜小了!")
    count -= 1

    # 控制猜的次数
    if count == 0:
        choice = input("是否继续玩,继续输入 y 或 Y ")
        if choice == 'y':
            count = 3

posted @   blueeeeeeeeeeee  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示