使用while打印1 2 3 4  5 6   8 9 10

count = 0
#while count < 10:
while count < 10:
count += 1
if count == 7:
print('')
else:
print(count)
测试
1
2
3
4
5
6 8
9
10

  使用while打印1 2 3 4 5 6 8 9 10;当count=7时不打印空格

while count < 10:
count += 1
if count == 7:
continue 返回重新开始
else:
print(count)
执行
1
2
3
4
5
6
8
9
10

  使用while打印1 2 3 4 5 6 8 9 10;当count=7时不打印空格,用pass

count = 0
#while count < 10:
while count < 10:
count += 1
if count == 7:
pass 跳过
else:
print(count)
执行测试 1
2
3
4
5
6
8
9
10

  使用while打印100以内的奇数

count = 1
while count < 101:
print(count)
count += 2
测试
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99

  打印 1-2+3-4+5....99打印结果

[root@es-3 ~]# cat test.py
sun = 0
count = 1
while count < 100:
if count % 2 == 0:
sun = sun - count
else:
sun = sun + count
count += 1
print(sun)
[root@es-3 ~]# python3 test.py
50

  格式化输出

name = input('请输入名字')
age = input('请输入年龄')
heigeht = input('请入身高')
msg = "我叫%s,今年%s,身高%s" %(name,age,heigeht) 占位符按顺序替换
print(msg)
[root@es-3 ~]# python3 test.py
请输入名字cd
请输入年龄98
请入身高90
我叫cd,今年98,身高90

  格式化输出二  只有%s 和%d

name = input('请输入名字')
age = input('请输入年龄')
job = input('请输入工作')
hobbie = input('你的爱好') msg = '''------------cx-------------
Name : %s
Age : %d 数字类型
job : %s
Hobbie : %s
---------------end----------------''' %(name,int(age),job,hobbie)
print(msg)
[root@es-3 ~]# python3 test.py
请输入名字cd
请输入年龄13
请输入工作erty
你的爱好yujnk
------------cx-------------
Name : cd
Age : 13
job : erty
Hobbie : yujnk
---------------end----------------

   格式化输出%

name = input('请输入姓名:')
age = input('请输入年龄:')
height = input('请输入身高:')
msg = "我叫%s,今年%d,身高%s,学习进度为3%%" %(name,int(age),height)
print(msg)
测试
[root@es-3 ~]# python3 test.py
请输入姓名:cx
请输入年龄:19
请输入身高:190
我叫cx,今年19,身高190,学习进度为3%

   pass 与break在while循环中的区别;当while循环被break打断,就不会执行else的语句了

count = 0
while count < 10:
count += 1
if count == 3:break 使用break直接中断后续操作
print (count)
else:
print (循环完成)
测试
C:\Users\zrd\AppData\Local\Programs\Python\Python37\python.exe G:/python/v/rt.py
1
2 count = 0
while count < 10:
count += 1
if count == 3:pass 结束本次判断
print (count)
else:
print ("循环完成") C:\Users\zrd\AppData\Local\Programs\Python\Python37\python.exe G:/python/v/test-2.py
1
2
3
4
5
6
7
8
9
10
循环完成

Python 基础-3的更多相关文章

  1. python之最强王者(2)——python基础语法

    背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...

  2. Python开发【第二篇】:Python基础知识

    Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...

  3. Python小白的发展之路之Python基础(一)

    Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...

  4. Python之路3【第一篇】Python基础

    本节内容 Python简介 Python安装 第一个Python程序 编程语言的分类 Python简介 1.Python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum) ...

  5. 进击的Python【第三章】:Python基础(三)

    Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...

  6. 进击的Python【第二章】:Python基础(二)

    Python基础(二) 本章内容 数据类型 数据运算 列表与元组的基本操作 字典的基本操作 字符编码与转码 模块初探 练习:购物车程序 一.数据类型 Python有五个标准的数据类型: Numbers ...

  7. Python之路【第一篇】python基础

    一.python开发 1.开发: 1)高级语言:python .Java .PHP. C#  Go ruby  c++  ===>字节码 2)低级语言:c .汇编 2.语言之间的对比: 1)py ...

  8. python基础之day1

    Python 简介 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. Python为我们提供了非常完善的基础代码库,覆盖了 ...

  9. python基础之文件读写

    python基础之文件读写 本节内容 os模块中文件以及目录的一些方法 文件的操作 目录的操作 1.os模块中文件以及目录的一些方法 python操作文件以及目录可以使用os模块的一些方法如下: 得到 ...

  10. python基础之编码问题

    python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode--->utf-8(utf-16和u ...

随机推荐

  1. Identity Server 4 原理和实战(完结)_Implicit Flow 实例

    oidc-client.js貌似是IdentityServer4的团队开发的 服务端的设置 在服务端新增一个Client 之后需要在angular客户端页建两个页面,对应这两个url才行 登出之后要跳 ...

  2. Identity Server 4 原理和实战(完结)_----选看 OpenId Connect 简介

    Identity Procider:身份提供商

  3. C# web 总结

    (1)Cshtml 中 “@” 符号转义 在 cshtml 中需要使用 “@” 符号,如 “@幸福摩天轮版权所有”.那么我们需要使用转义,使用 “@@” 就好!“© ”和 “@” 好像呀. <t ...

  4. 【OpenJ_Bailian - 4110】圣诞老人的礼物-Santa Clau’s Gifts (贪心)

    圣诞老人的礼物-Santa Clau’s Gifts  Descriptions: 圣诞节来临了,在城市A中圣诞老人准备分发糖果,现在有多箱不同的糖果,每箱糖果有自己的价值和重量,每箱糖果都可以拆分成 ...

  5. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:9. 自定义委托事件方法

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  6. IDEA快捷的添加包名

    Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题 2018年02月24日 17:24:49 _云卷云舒_ 阅读数:6264 标签: intellij idea 更 ...

  7. E - Multiplication Puzzle

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  8. 常用HTTP协议响应码(转载)

    转载于: https://blog.csdn.net/github_36032947/article/details/78343734 HTTP响应码,也称http状态码(HTTP Status Co ...

  9. mysql 主从 binlog

    binlog: 用来记录mysql的数据更新或者潜在更新(update xxx where id=x effect row 0);文件内容存储:/var/lib/mysql mysqlbinlog - ...

  10. 线段树-单点更新-HDU 1166 敌兵布阵

    #include <iostream> #include <cstdio> #include <string> #include <cstring> u ...