zoukankan      html  css  js  c++  java
  • if语句,while循环,for循环

    if语句:

    分支结构,选择结构

    # Author:Huan
    import getpass  #引入密文密码
    
    _username = 'Huan'
    _password = 'abc'
    username = input("name:")
    #password = getpass.getpass("password:")
    password = input("password:")
    
    if _username == username and _password == password:
        print("Welcome user {name} login...".format(name=username))
    else:
        print("Invaild username or password")
    
    print(username,password)

    while循环:

    基于某种条件循环到结束。

    # Author:Huan
    
    age_of_huan = 26
    count = 0
    while count < 3:
        guess_age = int(input("guess age:"))
        if guess_age == age_of_huan:
            print("yes,yo1u got it.")
            break
        elif guess_age > age_of_huan:
            print("think smaller...")
        else:
            print("think bigger...")
        count += 1
    else:
        print("you have tried too many times...")

    for循环:

    例1:

    for i in range(0,10):
        if i < 5:
            print("loop",i)
        else:
            continue    #跳出本次循环,进入下次循环
        print("hello...")

    例2:

    # Author:Huan
    
    age_of_huan = 26
    for i in range(3):
        guess_age = int(input("guess age:"))
        if guess_age == age_of_huan:
            print("yes,you got it.")
            break
        elif guess_age > age_of_huan:
            print("think smaller...")
        else:
            print("think bigger...")
    else:
        print("you have tried too many times...")

    continue:跳过循环的这一次循环,进行循环的下一次操作

    break:停止整个循环

  • 相关阅读:
    .gitignore不生效-git上传忽略解决方案的配置文件
    JAVA
    Java
    python-函数基础01
    Java常见数据结构
    分代垃圾回收机制及垃圾回收算法
    设计模式【9】------>观察者模式
    设计模式【8】------>策略模式
    设计模式【7】------>原型模式
    设计模式【6】------>外观模式
  • 原文地址:https://www.cnblogs.com/happystudyhuan/p/12271754.html
Copyright © 2011-2022 走看看