zoukankan      html  css  js  c++  java
  • while循环习题

    9.循环

      死循环

      while 1==1:

        print('ok')

    程序1-------------

    import time
    count = 0
    while count < 10:
      print('ok',time.time())
      count = count + 1
    print('final')

    程序2-------------

    求1--100的和

    a = 1
    b = 0
    while a < 101:
      b = b + a
      a = a + 1
    print(b)

    程序3---------

    输出1--100内所有的奇数

    a = 1
    while a < 101:
      if a % 2 == 1:
        print(a)
      else:
        pass
      a = a + 1

    程序4-------------------

    输出 1 2 3 4 5 6     8 9 10

    a = 1
      while a < 11:
      if a != 7:
        print(a)
      else:
        pass
      a = a + 1

    程序5---------

    输出 1---100之内所有的偶数

    a = 1
      while a < 101:
      if a % 2 ==0:
        print(a)
      else:
        pass
      a = a + 1

    程序6------------------

    输出1 - 2 + 3 - 4 + 5 - 6 …………- 98 + 99的结果

    a = 1
    b = 0
    while a < 100:
      if a % 2 == 1:
        b = b + a
      else:
        b = b - a
      a = a + 1
    print(b)

  • 相关阅读:
    beeline链接hive报错
    Java并发之FairSync和NonfairSync
    如何在 Linux 中将文件编码转换为 UTF-8
    Spring Boot运行原理
    jvm垃圾回收
    jvm调试工具
    Nginx相关
    docker 配置jar ,运行
    centos7的一些安装问题
    Docker
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8609058.html
Copyright © 2011-2022 走看看