• 猜年龄、模拟超级简单登陆系统(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
    在你说话之前,先听;在你回应之前,先想;在你消费之前,先挣;在你退出之前,先试
  • 相关阅读:
    设置vim查找高亮
    设置vim显示行号
    虚拟机安装VMware tools
    硬链接和软链接
    Ubuntu用户首次设置root用户的密码
    Ubuntu无法远程连接
    线上教育课堂如何解决H5视频点播转码出现的黑屏问题?
    “音视频+”时代到来,HLS(m3u8)/HTTP-FLV/RTSP流媒体RTMP推流服务器EasyDSS应用场景优化
    搭建一套完整的网络视频流媒体直播/点播服务系统需要具备哪些条件?
    关于网络视频流媒体直播/点播服务流程,你要知道的全在这里了!(新手必看)
  • 原文地址:https://www.cnblogs.com/sunweigogogo/p/7487770.html
Copyright © 2020-2023  润新知