博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
while循环习题
阅读量:7072 次
发布时间:2019-06-28

本文共 801 字,大约阅读时间需要 2 分钟。

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)

 

转载于:https://www.cnblogs.com/lhqlhq/p/8609058.html

你可能感兴趣的文章
运行及总结
查看>>
怎么才能少奋斗10年
查看>>
QTableWidget与QTableView的区别
查看>>
关于SQL Server 中连接查询Join的几种常见用法
查看>>
Selenium学习之==>Switch与SelectApi接口详解
查看>>
Js判断是否是直接进入本页面的
查看>>
GOlang eclipse install
查看>>
Centos7 hostname重启失效
查看>>
Postgre SQL连接服务器失败
查看>>
小程序之短信验证
查看>>
App Store优化推广 如何提高海外搜索排名
查看>>
POJ3580 SuperMemo(Splay的区间操作)
查看>>
Android Service解析
查看>>
elasticsearch快速入门
查看>>
CentOS7-部署kubernetes
查看>>
hdu 4001 To Miss Our Children Time( sort + DP )
查看>>
日常note
查看>>
Leetcode 727. Minimum Window Subsequence
查看>>
java切换jdk版本
查看>>
hdu 1005 Number Sequence zoj 1105
查看>>