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)

    输出结果:

  • 相关阅读:
    POJ 3349 HASH
    POJ 1840 HASH
    POJ 2785 HASH
    HDU 3926 图的同构
    POJ 2549 二分+HASH
    POJ 2002 统计正方形 HASH
    POJ 1971 统计平行四边形 HASH
    POJ 1635 树的最小表示法/HASH
    POJ 1200 字符串HASH
    ACM学习历程—HDU 1272 小希的迷宫(并查集)
  • 原文地址:https://www.cnblogs.com/shannon-V/p/9556085.html
Copyright © 2011-2022 走看看