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)

    输出结果:

  • 相关阅读:
    ege demo
    Easy Graphics Engine vs2015使用
    c++ demo
    leetcode 13 -> Roman to Integer
    leetcode 12 -> Integer to Roman
    12. Integer to Roman
    leetcode 9 -> Palindrome Number
    8. String to Integer (atoi)
    获取字符串中长度最长的回文字符串
    leetcode 5-> Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/shannon-V/p/9556085.html
Copyright © 2011-2022 走看看