作业:

1.使用while循环输入1 2 3 4 5 6 8 9 10(没有7)

n = 1
while n < 11:
if n == 7:
pass
else:
print(n)
n = n + 1
print('结束')

2.求1-100所有数的和

n = 1
s = 0
while n < 101:
s = s + n
n = n + 1
print(s)

3.输出1-100的所有奇数

n = 1
while n <101:
print(n)
n = n + 2
print('结束')
n = 1
while n <101:
temp = n % 2
if temp == 0:
pass
else:
print(n)
n = n + 2
print('结束')

4.输出1-100的所有偶数

n = 1
while n < 101:
temp = n % 2
if temp == 0:
print(n)
else:
pass
n = n + 1
print('结束')

5.求1-2+3-4+5...99的所有的数的和

n = 1
s = 0
while n < 101:
temp = n % 2
if temp == 0:
s = s - n
else:
s = s + n
n = n + 1
print(n)

6.用户登录(三次机会重试)

count = 0
while count < 3:
user = input('请输入用户名')
pwd = input('请输入密码')
if user == 'alex' and pwd == '':
print('欢迎登录')
break
else:
print('用户名或密码错误')
count = count + 1

注意:1.如果if语句里面加and,只需要在最后输入一个冒号:

        2.IF下面的代码块注意空格一致

7.补充:a. while else 

count =
while count < :
print(count)
count = count +
else:
print('else')

        b.continue(终止当前循环开始下一次循环)

count =
while count < :
if count == :
count = count +
continue
print(count)
count = count +

注意:如果符合条件那么continue下面的代码都不再执行!

            c.break(终止所有循环直接跳出)

count = 0
while count < 10:
count = count + 1
print(count)
break
print('haha')
print('hehe')

8.死循环:

注意最后print的是否空格区别。

count = 0
while count < 10:
  print('继续运行')
  count = count + 1
print('结束运行')

最新文章

  1. PPPoE(以太网上的点对点协议)
  2. Java中如何解决double和float精度不准的问题
  3. p188习题2
  4. Hibernate个人总结
  5. 2014年度辛星html教程夏季版第五节
  6. c语言学习之基础知识点介绍(二十):预处理指令
  7. 访问的是A网址,但是跳转B网址的内容,地址栏还是A网址
  8. c++中多态性、dynamic_cast、父类指针、父类对象、子类指针、子类对象
  9. 关于GROUP BY的应用
  10. 《算法》C/C++ 图形处理
  11. ListView 无 DataSource 依然用 DataPager 翻页
  12. python之模块、包的导入过程和开发规范
  13. mongoDB3.0版本使用express读取数据
  14. thinkphp微信浏览器内拉起微信支付
  15. Spring data Jpa,Mybatis,读写锁,@Lock 使用
  16. linux_shell使用
  17. Spring 配置文件
  18. Lagrange 乘子法求最优解
  19. PythonCharm 配置本地反向代理激活
  20. 照着官网来安装openstack pike之创建并启动instance

热门文章

  1. 洛谷1758 BZOJ1566 管道取珠题解
  2. poj 1655 Balancing Act 求树的重心【树形dp】
  3. vue页面内监听路由变化
  4. 数组工具类 Day07
  5. QT 开发ros gui过程中遇到:error: catkin_package() include dir &#39;include&#39; does not exist relative to &#39;/home/jun/catkin_ws/src/qt_ros_test&#39; /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_p
  6. js中setInterval与setTimeout用法 实现实时刷新每秒刷新
  7. UISearchDisplayController “No Results“ cancel修改
  8. hdu 3873 Invade the Mars(有限制的最短路 spfa+容器)
  9. 2016国产开源软件Top100(Q1)
  10. SuperSocket 服务器管理器 (ServerManager)