• Python 基础01


    猜年龄 , 可以让用户最多猜三次!


    #!/bin/python3
    # -*- coding:utf-8 -*-
    age = 56
    times = 3
    guess = 0
    while guess != 3:
        user_guess = int(input("input your guess age:"))
        if user_guess > age :
            print("try smaller!")
            guess += 1
        elif user_guess < age :
            print("try bigger!")
            guess += 1
        else:
            print("you got it!")
            break
    if guess == 3:
    	print("only can guess three times!")
    

    猜年龄 ,每隔3次,问他一下,还想不想继续玩,y,n


    #!/bin/python3
    # -*- coding:utf-8 -*-
    age = 56
    while True:
    	guess = 0
    	while guess != 3:
    	    user_guess = int(input("input your guess age:"))
    	    if user_guess > age :
    	        print("try smaller!")
    	        guess += 1
    	    elif user_guess < age :
    	        print("try bigger!")
    	        guess += 1
    	    else:
    	        print("you got it!")
    	        break
    	if guess == 3:
    		print("only can guess three times!")
    	flag = input("continue play?y/n:")
    	if flag == 'n' or flag == 'N':
    		break
    

    登陆接口


    输入用户名密码,认证成功后显示欢迎信息,输错三次后锁定

    #!/bin/python3
    # -*- coding:utf-8 -*-
    #调用
    import getpass,os
    def read_users(username):
    	flag = 1
    	user_list = open('userlockd.txt', 'r')
    	while True:
    		line=user_list.readline()
    		if len(line.strip()) == 0:
    			break
    		if line.strip() == username:
    			flag = 0
    			break
    	return flag
    def lock_user(username):
    	user_list = open('userlockd.txt','w+')
    	user_list.writelines(username)
    
    times = 0
    while True:
    	username = input("username:")
    	password = getpass.getpass("password:")
    	if read_users(username):
    		if username == "sbegon" and password == "123":
    			print("welcome %s" %username)
    			break
    		elif times == 2:
    			print("wrong username or password!this account has been locked!")
    			lock_user(username)
    			break
    		else:
    			print("wrong username or password!")
    			times += 1
    	else:
    		print("this account has been locked")
    		break
    
  • 相关阅读:
    2017-4-6校内训练
    [BZOJ]1023: [SHOI2008]cactus仙人掌图
    [BZOJ]1086: [SCOI2005]王室联邦
    [BZOJ]1055: [HAOI2008]玩具取名
    [BZOJ]3527: [Zjoi2014]力
    [BZOJ]2820: YY的GCD
    【BZOJ3233】【tyvj1729】文艺平衡树
    【数据结构】【平衡树】无旋转treap
    【BZOJ2733】【HNOI2012】永无乡
    【BZOJ3224】【tyvj1728】普通平衡树
  • 原文地址:https://www.cnblogs.com/anyanyaaaa/p/6627502.html
Copyright © 2020-2023  润新知