葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌先锋网 葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌片段及技术文章聚合

一段欢迎用户的葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌

import json
filename = 'verify_name.json'

def get_load_name():
    """获取用户名称"""
    try:
        with open(filename) as name_obj:
            name = json.load(name_obj)
            return name
    except FileNotFoundError:
        return None

def get_new_name():
    """获取新用户名称"""
    with open(filename, 'w') as name_obj:
        new_name = input("what's your name ? ")
        json.dump(new_name, name_obj)
        print("I'll remember you")
    return new_name

def verify_user(name):
    """询问用户是否为获取到的用户名"""
    verify = input("are you " + name + " ?" + "Y/N")
    while verify != 'N' and verify != 'Y':
        print("please enter 'Y' or 'N'. ")
        verify = input()
    if verify == 'N':
        get_new_name()
    else:
        print("Welcome back " + name + " !")

def greet_user():
    """欢迎用户"""
    name = get_load_name()
    if name:
        verify_user(name)
    else:
        get_new_name()

greet_user()

原文地址:一段欢迎用户的葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌