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
    在你说话之前,先听;在你回应之前,先想;在你消费之前,先挣;在你退出之前,先试
  • 相关阅读:
    小小不爽一下
    银行家算法的讨论
    【转】C字符串处理函数的实现
    Oracle物理存储结构文件
    RAC和ASM环境下修改控制文件control file
    TNS01190: The user is not authorized to execute the requested listener comm (oracle”用户没有启动lisener的权限?)
    RAC环境ASM存储新增控制文件的方法
    Oracle RAC 修改 spfile 文件位置
    Rman通过duplicate创建standby
    rman恢复手册
  • 原文地址:https://www.cnblogs.com/sunweigogogo/p/7487770.html
Copyright © 2011-2022 走看看