zoukankan      html  css  js  c++  java
  • python学习13——while循环。

    i = 0
    numbers = []
    while i < 6:
     print("At the top i is %d." %i)
     numbers.append(i)
     i = i + 1
     print("Numbers now:", numbers)
     print("At the bottom i is %d." % i)
    print("The numbers:")
    for num in numbers:
     print (num)

    输出结果:

    将数字6i 的增加值改成一个需要手动输入的值:

    i = 0
    numbers = []
    a = int(input("Please enter a number:"))
    while i < a:
     print("At the top i is %d." %i)
     numbers.append(i)
     b = int(input("Please enter a number again:"))
     i = i + b
     print("Numbers now:", numbers)
     print("At the bottom i is %d." % i)
    print("The numbers:")
    for num in numbers:
     print (num)

    将while 改为 for

    numbers_2 = []
    c = int(input("Please enter a number:"))
    for i in range(c):
     print("At the top i is %d." %i)
     numbers_2.append(i)
     print("Numbers now:")
     print("At the bottom i is %d."% i)
    print ("The numbers:")
    for num in numbers_2:
     print(num)

    输出结果:

    将加值操作去掉:

    numbers_2 = []
    c = int(input("Please enter a number:"))
    for i in range(c):
     print("At the top i is %d." %i)
     
     print("Numbers now:")
     print("At the bottom i is %d."% i)

    输出结果:

  • 相关阅读:
    iOS
    关于HTTP协议学习(三)
    关于HTTP协议学习(二)
    关于HTTP协议学习(一)
    Swift之Swift编码规范
    老罗学习MVC之旅:MVC组件分析
    android 左右翻页
    android 检测网络是否可用
    android 在线升级借助开源中国App源码
    android 渐变展示启动屏
  • 原文地址:https://www.cnblogs.com/shannon-V/p/9556085.html
Copyright © 2011-2022 走看看