Python 基础-3
使用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的更多相关文章
- python之最强王者(2)——python基础语法
背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...
- Python开发【第二篇】:Python基础知识
Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...
- Python小白的发展之路之Python基础(一)
Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...
- Python之路3【第一篇】Python基础
本节内容 Python简介 Python安装 第一个Python程序 编程语言的分类 Python简介 1.Python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum) ...
- 进击的Python【第三章】:Python基础(三)
Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...
- 进击的Python【第二章】:Python基础(二)
Python基础(二) 本章内容 数据类型 数据运算 列表与元组的基本操作 字典的基本操作 字符编码与转码 模块初探 练习:购物车程序 一.数据类型 Python有五个标准的数据类型: Numbers ...
- Python之路【第一篇】python基础
一.python开发 1.开发: 1)高级语言:python .Java .PHP. C# Go ruby c++ ===>字节码 2)低级语言:c .汇编 2.语言之间的对比: 1)py ...
- python基础之day1
Python 简介 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. Python为我们提供了非常完善的基础代码库,覆盖了 ...
- python基础之文件读写
python基础之文件读写 本节内容 os模块中文件以及目录的一些方法 文件的操作 目录的操作 1.os模块中文件以及目录的一些方法 python操作文件以及目录可以使用os模块的一些方法如下: 得到 ...
- python基础之编码问题
python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode--->utf-8(utf-16和u ...
随机推荐
- POJ - 2251 Dungeon Master 多维多方向BFS
Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is ...
- 查看python 3中的内置函数列表,以及函数功能描述
>>> dir(__builtins__)//查看内置函数(BIF)列表 ['ArithmeticError', 'AssertionError', 'AttributeError' ...
- laravel MVC分布及数据库配置
laravel MVC分布 M app\Http\Middleware V resources\views C app\Http\Controllers 数据库配置 目录 config\datab ...
- Android DPAD not enabled in AVD
问题描述:打开Android的仿真器,右侧的按键部分对于上下左右键出现以下现象后果是,这些按键都没法使用,由于我是测试一个小游戏,俄罗斯方块,朋友,要是少了上下左右键,让我情何以堪,而且我试过使用键盘 ...
- __setitem__,__getitem,__delitem__
目录 __setitem__ __getitem__ __delitem__与__delattr__ class Foo: def __init__(self, name): self.name = ...
- LeetCode.905-按奇偶排序数组(Sort Array By Parity)
这是悦乐书的第347次更新,第371篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第212题(顺位题号是905).给定一个非负整数数组A,返回一个由A的所有偶数元素组成的 ...
- C#邮包计费
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- echarts相关属性设置(1)折线图篇
option = { tooltip: { trigger: 'axis', // axisPointer: { // type: 'cross', // label: { // background ...
- VLAN-4-在路由器上配置Trunk
VLAN Trunk技术可以用在路由器和主机上,也可以用在交换机上.路由器不支持DTP,所以工程师必须手动配置. 路由器Trunk需要使用子接口(在一个接口中实现多个vlan间的路由和通信),每个子接 ...
- gns3 拖出设备显示一个红色的s,无法启动虚拟设备
通过view-docks-调出console窗口,显示错误信息: Error while creating project: Can't connect to server http://172.0. ...