11-while循环基本使用
hm_02_第一个while循环.py
def main():
i = 1
while i <= 3:
print(i, 'Hello world')
i += 1
print(i)
1 Hello world
2 Hello world
3 Hello world
4
hm_03_程序计数.py
def main():
i = 0
while i < 3:
print(i, 'Hello world')
i += 1
print(i)
hm_04_累加求和.py
def main():
sum = 0
i = 0
while i <= 100:
sum += i
i += 1
print(i, sum)
101 5050
hm_05_偶数求和.py
def main():
sum = 0
i = 0
while i <= 100:
if i % 2 == 0:
print(i)
sum += i
i += 1
print(i, sum)
101 2550
hm_06_break.py
def main():
i = 0
while i < 10:
if i == 3:
break
print(i)
i += 1
0
1
2
hm_07_continue.py
def main():
i = 0
while i < 10:
if i == 3:
i += 1
continue
print(i)
i += 1
0
1
2
4
5
6
7
8
9
hm_08_打印小星星.py
def main():
row = 0
while row <= 5:
print('*' * row)
row += 1
*
**
***
****
*****
hm_09_print函数的结尾.py
def main():
print('*' * 10, end='---')
**********---
hm_10_嵌套打印小星星.py
def main():
row = 0
while row < 5:
col = 0
while col <= row:
print('*', end='')
col += 1
print('')
row += 1
hm_11_九九乘法表.py
def main():
row = 1
while row <= 9:
col = 1
while col <= row:
print('%d*%d=%d' % (col, row, col * row), end='\t')
col += 1
print('')
row += 1
hm_12_转义字符.py
def main():
print('1\t2')
print('hello\nworld')
11-while循环基本使用的更多相关文章
- [C++11]shared_ptr循环引用导致内存泄露
1 /* 2 * shared_ptr循环引用导致内存泄露 3 */ 4 5 struct A 6 { 7 shared_ptr<A> ptr; // 改为weak_ptr<A> ...
- SSIS - 11.For循环容器
一.For循环容器中的3个循环变量 For循环容器,类似于编程语言中的For,用于重复执行容器内的任务,直到条件返回为False.与编程语言类似,For循环容器也需要定义以下3种循环属性: 注: 必须 ...
- 2.11 while循环的嵌套以及应用(难)
while循环嵌套 前面学习过if的嵌套了,想一想if嵌套是什么样子的? 类似if的嵌套,while嵌套就是:while里面还有while <1>while嵌套的格式 while 条件1: ...
- 11.js循环与函数
Switch语句 Switch(变量){ : 如果变量和1的值相同,执行该处代码 break; : 如果变量和2的值相同,执行该处代码 break; : 如果变量和3的值相同,执行该处代码 break ...
- 【python系统学习11】循环语句里的F4
循环语句里的F4 深入了解下四个新语句,分别是:continue.break.pass.else以及他们搭配for.while循环等语句时,所产生的化学反应. else 由于continue.brea ...
- c++11之一: 基于范围的for循环
#include <iostream> using namespace std; int main(){ ]{,,,,}; for (int& e: ary) e *= ; for ...
- python之最强王者(3)——变量,条件、循环语句
1.Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的 ...
- 一步一步学python(五) -条件 循环和其他语句
1.print 使用逗号输出 - 打印多个表达式也是可行的,但要用逗号隔开 >>> print 'chentongxin',23 SyntaxError: invalid synta ...
- Python之collections序列迭代器下标式循环冒泡算法等
练习题 元素分类 有如下值集合[11,22,33,44,55,66,77,88,99]将所有大于66的数作为一个列表放在字典的key为k1的value小于等于66的为k2的value {'k1':[7 ...
- HDU1005 找规律 or 循环点 or 矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=1005 1.一开始就注意到了n的数据范围 <=100 000 000,但是还是用普通的循环做的,自然TLE了 ...
随机推荐
- django的orm操作的补充
---恢复内容开始--- 你在建立一个登陆的时候需要用到auth这个用户登陆模块 这个时候就需要用到user表中的信息你就可以继承 这个时候我们的用户表中继承我们user继承的表 ABstractUs ...
- c#listbox使用详解和常见问题解决
关于ListBox ListBox是WinForm中的 列表 控件,它提供了一个项目列表(一组数据项),用户可以选择一个或者多个条目,当列表项目过多时,ListBox会自动添加滚动条,使用户可以滚动查 ...
- Asp.Net MVC Identity 2.2.1 使用技巧(四)
使用用户管理器之用户管理 一.建立模型 1.在Models文件夹上点右键 >添加>类 类的名称自定,我用AdminViewModels命名的. 2.更改模板自建的AdminView ...
- java基础易混点
1.进制转换由低到高:byte<short(char)<int<long<float<double 2.java八种基本数据类型(存在栈里): 整数类型 byte,s ...
- Intellij IDEA常用快捷键和一些配置——Mac版
常用的快捷键 代码补全Ctrl + space 删除行Command + D 注释Command + / 导入包Command + shift + O 格式化代码Command + shift + F ...
- 使用python 操作liunx的svn,方案二
在对liunx操作svn的方式,做了改动,使用python的,subprocess进行操作 在第一种方案中,我使用了先拉到本地,然后再创建,在进行上传,实际在svn中可以直接创建文件,并进行文件复制, ...
- Java List详解,面试中应该如何解答关于List的问题
对于面试,我们在介绍Java的List的时候,一般需要介绍到,什么是List?List包括什么?各自在用法上有什么区别,在存储上有什么区别?List需要注意什么?把这些问题串起来,我们可以这样介绍: ...
- Java并发案例03---生产者消费者问题02
生产者消费者第二种情形 package com.maple.msb.one; public class ProducerConsumer { public static void main(Strin ...
- Asp.net Web Api添加异常筛选器
一.定义一个异常筛选器 using System;using System.Collections.Generic;using System.Linq;using System.Web;using S ...
- 【php】php与mysql初体验
第一次体验在web站点上使用MySQL数据库,遇到了很多问题,总结如下: 1.安装XAMPP软件后,将文件放到hotdocs文件夹下,要访问其中的文件,使用localhost/XXX/XXX ,路径要 ...