• Python基础(2)


    Python基础二:

    for循环:

    for i in  range(0,10,2):

      prin(i)

    else:

      print(“结束!!”)

    for循环正常结束,执行else语句,否则不执行。

    if语句:

    age_of_oldboy=56
    guess_age=int(input("guess age:"))
    if guess_age==age_of_oldboy:
    print("Yes,you got it.")
    elif guess_age > age_of_oldboy:
    print("Think smaller...")
    else:
    print("Think bigger!")

    循环套循环:
    for i in range(10):
    print("---------",i)
    for j in range(10):
    print(j)
    if j > 5:
    break
    #break结束整个循环。
    continue:
    for i in range(10):
    if i < 5:
    print(i)
    else:
    continue
    print("hehe")

    猜名字:
    # Author:GaoYuCai
    count=0
    age_of_oldboy=56
    while count <3:
    guess_age=int(input("guess age:"))
    if guess_age== age_of_oldboy:
    print("Yes,you are right!")
    break
    elif guess_age< age_of_oldboy:
    print("Think smaller!")
    else:
    print("think biggest!")
    count=count+1
    if count==3:
    sw=input("Do you want continue? y/n:")
    if sw=="y":
    count=0
    else:
    break


  • 相关阅读:
    倍数求和
    最大(小)值
    数组扁平化:(多维数组 -> 一维数组)
    任意数求和
    找到重复最多项
    Linux 标准 I/O 库
    Linux文件操作函数
    Linux文件的IO操作 一
    Linux文件系统概述二
    Linux文件系统概述
  • 原文地址:https://www.cnblogs.com/gycone/p/10143175.html
Copyright © 2020-2023  润新知