zoukankan      html  css  js  c++  java
  • 猜年龄、模拟超级简单登陆系统(getpass、while、if、else、elif、for)

    #/usr/bin/env python
    #getpass用法
    import getpass
    _username = "test"
    _password = "passwd"
    
    username = getpass.getpass("your name is:")
    password = getpass.getpass("your passwd is:")
    
    print(username,password)
    
    if _username == username and _password == password:
        print("Welcome system of {name}" .format(name=username))
    else:
        print("invalid username or password...")
    #猜年龄(while if else elif for)
    #example 1
    age_of_test = 34
    while True:
        guess_age = int(input("guess age:"))
    
        if guess_age == age_of_test:
            print("yes,you got it...")
            break
        elif guess_age > age_of_test:
            print("no,think smaller...")
        else:
            print("no,think bigger...")
    #example 2
    age_of_test = 34
    count = 0
    while True:
        if count == 3:
            break
        guess_age = int(input("guess age:"))
        if guess_age == age_of_test:
            print("yes,you got it...")
            break
        elif guess_age > age_of_test:
            print("no,think smaller...")
        else:
            print("no,think bigger...")
        count +=1
    #example 3
    age_of_test = 34
    count = 0
    while count < 3:
        guess_age = int(input("guess age:"))
        if guess_age == age_of_test:
            print("yes,you got it...")
            break
        elif guess_age > age_of_test:
            print("no,think smaller...")
        else:
            print("no,think bigger...")
        count +=1
    #写法1
    #if count == 3:
    #写法2
    else:
        print("you have tried too many times...")
    #example 4
    age_of_test = 34
    for i in range(3):
        guess_age = int(input("guess age:"))
        if guess_age == age_of_test:
            print("yes you got it...")
            break
        elif guess_age > age_of_test:
            print("no,think smaller...")
        else:
            print("no,think bigger...")
    else:
        print("you havd tried many times...")
    #example 5
    count = 0
    age_of_test = 34
    
    while count < 3:
        guess_age=int(input("guess age:"))
        if age_of_test == guess_age:
            print("yes,you got it...")
            break
        elif guess_age > age_of_test:
            print("no,think smaller...")
        else:
            print("no,think bigger...")
        count +=1
        if  count == 3:
            continue_confirm = input("do you want to continue thinking...
    ")
            if continue_confirm != "n":
                count = 0
    在你说话之前,先听;在你回应之前,先想;在你消费之前,先挣;在你退出之前,先试
  • 相关阅读:
    linux的find命令详解
    在接口中的静态方法来获取model的实例对象
    php函数decbin
    cookie的默认有效目录
    html的base标签
    mysql多位小数字段用decimal类型
    vmware在桥接模式下配置centos7网络
    iis_rewrite3突然无法使用(因为它过期啦)
    LightGBM 调参方法(具体操作)
    沪深股票的复权计算(复权因子的应用)--代码实现
  • 原文地址:https://www.cnblogs.com/sunweigogogo/p/7487770.html
Copyright © 2011-2022 走看看