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:停止整个循环

  • 相关阅读:
    RecyclerView+CardView简单使用
    Android六大进程间通信方式总结之一:基本知识
    前台服务
    Notification
    SQLite的基本用法
    SharePreferences基本用法
    自定义控件和使用的两种基本方法
    AsyncTask的简单使用
    Java Servlet调用数据库复习
    JDBC数据源(DataSource)的简单实现
  • 原文地址:https://www.cnblogs.com/happystudyhuan/p/12271754.html
Copyright © 2011-2022 走看看