一、内容

二、练习

练习1

题目:已知msg='hello knight 666'编写for循环,利用索引遍历出每一个字符

图示:

代码:

msg = 'hello knight 666'
msg_len = len(msg)
for i in range(msg_len):
print(msg[i])

输出结果:

h
e
l
l
o k
n
i
g
h
t 6
6
6

练习2

题目:已知msg='hello knight 666'编写for循环,利用索引遍历出每一个字符

图示:

代码:

msg = 'hello knight 666'
count = 0
while True:
print(msg[count])
count += 1
if count == len(msg):
break

输出结果:

h
e
l
l
o k
n
i
g
h
t 6
6
6

练习3

题目:已知变量msg='hello qishi',将msg中的qishi替换成knight

代码:

msg='hello qishi'
msg_new = msg.replace('qishi','knight')
print(msg_new)

输出结果:

hello knight

练习4

题目:已知 msg='/etc/a.txt|365|get' 将该字符的文件名,文件大小,操作方法切割出来。

代码:

msg ='/etc/a.txt|365|get'
msg_new = msg.split('|')
print('文件名:',msg_new[0])
print('文件大小:',msg_new[1])
print('操作方法:',msg_new[2])

输出结果:

文件名: /etc/a.txt
文件大小: 365
操作方法: get

练习5

题目:编写while循环,要求用户输入命令,如果命令为空,则继续输入

图示:

代码:

count = 0
while True:
user_input = input('Please enter command:').strip()
if not user_input:
continue
print('The cmd is %s'%user_input)

练习6

题目:编写while循环,让用户输入用户名和密码,如果用户为空或者数字,则重新输入

图示:

代码:

while True:
user = input('Please enter username:').strip()
password = input('Please enter password:')
if not user or user.isdigit():
print('The username you entered is blank, please re-enter')
continue
print('Welcome %s'%user)
break

练习7

题目:编写while循环,让用户输入内容,判断输入的内容以knight开头的,则将该字符串加上_successful结尾

图示:

代码1:

while True:
user = input('Please enter:').strip()
if user.startswith('knight'):
print(user+'_successful')

代码2:

while True:
user = input('Please enter:').strip()
if user.startswith('knight'):
print('%s%s'%(user,'_successful'))

练习8

题目:

(1)两层while循环,外层的while循环,让用户输入用户名、密码、工作了几个月、每月的工资(整数),用户名或密码为空,或者工作的月数不为整数,或者月工资不为整数,则重新输入

(2)认证成功,进入下一层while循环,打印命令提示,有查询总工资,查询用户身份(如果用户名为knight则打印super user,如果用户名为tangbao或者zhuozi则打印normal user,其余情况均打印unknown user),退出功能

(3)要求用户输入退出,则退出所有循环(使用tag的方式)

图示:

代码:

user_info = ['knight','zhuozi','tangbao']
tag = True
while tag:
username = input('Please enter username:').strip()
password = input('Please enter password:')
if not username or not password:
print('Your account or password is blank, please re-enter')
continue
month = input('Please enter the month:').strip()
salary = input('Please enter the salary:').strip()
if not month.isdigit() or not salary.isdigit():
print('The month or salary you enter must be an integer.')
if username == 'root' and password == '123456':
print('Login successfully!')
while tag:
print('请选择以下功能\n1、查询用户功能\n2、查询总工资功能\n3、退出')
cmd = input('Please select function:').strip()
if cmd == '1':
user = input('Please enter username:').strip()
if user == 'knight':
print('super user')
elif user == 'tangbao' or user == 'zhuozi':
print('normal user')
else:
print('known user')
elif cmd =='2':
print('Your total salary is %s'%(int(month)*int(salary)))
elif cmd =='3':
print('Goodbye!')
tag = False
else:
print('Invalid command,please try again!')
else:
print('Sorry,your account or password is incorrect,please try again!')

三、英语

1、invalid

[ˈɪnvəlɪd;ɪnˈvælɪd]    adj.无效的

2、item

['aɪtəm]    n.项目

3、incorrect

[,ɪnkə'rɛkt]    adj. 错误的,不正确的

4、range

[rendʒ]    n. 范围

5、parameter

[pə'ræmɪtɚ]    n. 参数

6、error

['ɛrɚ]    n.错误

7、step

[stɛp]    n.步

8、setting

['sɛtɪŋ]    v.设定

9、key

[kiː]    n.键

10、value

['vælju]    n.值

11、increase

['ɪnkris]    v.增加

12、decrease

[dɪ'kris]    v.减少

13、script

[skrɪpt]    n.脚本

14、font

[fɑnt]    n. 字体

15、type

[taɪp]    n.类型

16、strip

[strɪp]    vt.剥离;脱去

17、split

[splɪt]    vt.分割

18、count

[kaʊnt]    vt.计数

19、continue

[kən'tɪnju]    vi. 继续

20、break

[brek]    vi.打断

Python基础第二天的更多相关文章

  1. python基础-第二篇-基本数据类型

    一.运算符 1.算数运算: 算数运算符相信大家都不陌生吧,尤其是加减乘除,好!那我就带着大家看看最后三个,这三个到底是干什么玩意的? %,取两数相除的余数,看图: **,x的多少次幂,看图: //,取 ...

  2. Python基础第二篇

    一.三元运算 if True: name='a' else: name='b' #上面的代码用三元运算表示: name="a" if True else "b" ...

  3. Python基础 第二天

    1.http://www.cnblogs.com/beer/p/5672678.html requests和beautifulsoup

  4. Python基础第二课

    字符串(引号):四种表达方式 n1 = "我是" n1 = '我是' n1 = """我是""" n1 = '" ...

  5. python基础(二)----数据类型

    Python基础第二章 二进制 字符编码 基本数据类型-数字 基本数据类型-字符串 基本数据类型-列表 基本数据类型-元组 可变.不可变数据类型和hash 基本数据类型-字典 基本数据类型-集合 二进 ...

  6. Python之路【第二篇】:Python基础

    参考链接:老师 BLOG : http://www.cnblogs.com/wupeiqi/articles/4906230.html 入门拾遗 一.作用域 只要变量在内存中就能被调用!但是(函数的栈 ...

  7. Python之路【第二篇】:Python基础(一)

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1:     name = 'wupeiqi' print  name 下面的结论对吗? ...

  8. 第二章:python基础,数据类型

    """第二章:python基础,数据类型2.1 变量及身份运算补充2.2 二进制数2.3 字符编码每8位所占的空间位一个比特,这是计算机中最小的表示单位.每8个比特组成一 ...

  9. 《python基础教程(第二版)》学习笔记 文件和素材(第11章)

    <python基础教程(第二版)>学习笔记 文件和素材(第11章) 打开文件:open(filename[,mode[,buffering]]) mode是读写文件的模式f=open(r' ...

随机推荐

  1. 十款开发者常用的Chrome插件,让chrome成为开发利器!

    Chrome浏览器无论是作为浏览器市场的NO1还是其强大的跨平台能力以及丰富的扩展插件,一直是许多开发者的首要选择的浏览器.chrome浏览器也因为其丰富的Chrome插件,帮助开发者们在开发流程中极 ...

  2. 1001. A+B Format (20) (%0nd)

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...

  3. MTK平台释疑android M 配置中断相关问题

    1.使用老方法(android L)配置中断,调用request_irq函数时出错,错误代码 -22  Dear Customer: 您好! 如电话沟通,贵司可以在发过来的code基础上做下面的修改再 ...

  4. TKmybatis的框架介绍和原理分析及Mybatis新特性

    tkmybatis是在mybatis框架的基础上提供了很多工具,让开发更加高效,下面来看看这个框架的基本使用,后面会对相关源码进行分析,感兴趣的同学可以看一下,挺不错的一个工具 实现对员工表的增删改查 ...

  5. next_permitation

    了解一个C++ STL的函数 next_permitation 可用于生成全排列 如下例子 #include <iostream> #include <stdio.h> #in ...

  6. 洛谷 P4136 谁能赢呢?

    P4136 谁能赢呢? 题目描述 小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移 ...

  7. 图片在 canvas 中的 选中/平移/缩放/旋转,包含了所有canvas的2D变化,让你认识到数学的重要性

    1.介绍 canvas 已经出来好久了,相信大家多少都有接触. 如果你是前端页面开发/移动开发,那么你肯定会有做过图片上传处理,图片优化,以及图片合成,这些都是可以用 canvas 实现的. 如果你是 ...

  8. openstack setup demo Image service

    Image service (glance)是openstack中管理vm image的service.本文包含以下内容: overview install overview glance包含以下部分 ...

  9. CodeForces484A Bits(贪心)

    CodeForces484A Bits(贪心) CodeForces484A 题目大意:给出范围[A.B].期望你给出某个数X满足X属于[A,B],而且X转成二进制的1的个数最多.假设有多个给出最小的 ...

  10. create-react-app 引入 antd 及 解决 antd 样式无法显示的bug

    方案一: npm run eject 暴露所有内建的配置 安装组件库 yarn add antd babel-plugin-import 根目录下新建.roadhogrc文件(别忘了前面的点,这是ro ...