zoukankan      html  css  js  c++  java
  • Python控制流语句(if,while,for)

    if.py

    number=23
    guess=int(input("enter an int:"))
    if guess==number:
        print ("congratulations, you guessed it.")
    elif guess<number:
        print ("No, it's a little higher than that")
    else:
        print ("No, it's a little lower than that")
    
    print ("done")
    

    while.py

    number=23
    running=True
    
    while running:
        guess=int(input("input an integer:"))
        if guess==number:
            print("congs, you guessed it")
            running=False
        elif guess>number:
            print ("No, it's a little higher")
        else:
            print ("No, it's a little lower")
    else:
        print("the while loop is over.")
    print ("done")
    

    for.py

    for i in range(1,10):
        print (i)
    else:
        print ("the for loop is over")
    

    break.py

    while True:
        s = input('Enter something : ')
        if s == 'quit':
            break
        print ('Length of the string is', len(s))
    print ('Done')
    

    continue.py

    while True:
        s=input('enter something:')
        if s=='quit':
            print ('you are quit from program')
            break
        if len(s)<3:
            print ('input is',s)
            continue
        print ('input is of sufficient length')
    print ('the program is over')
    
  • 相关阅读:
    iOS 学习
    iOS 学习
    textField和textView限制输入条件
    FMDB的使用
    Xcode7以后 使用空模板
    MJPhotoBrowser BUG修复
    获得通讯录的访问权
    正则运算校验手机号码
    项目中生产模式和开发模式的切换
    自定义的进度条
  • 原文地址:https://www.cnblogs.com/oskb/p/5065826.html
Copyright © 2011-2022 走看看