一、内容

二、练习

练习1

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

图示:

代码:

  1. msg = 'hello knight 666'
  2. msg_len = len(msg)
  3. for i in range(msg_len):
  4. print(msg[i])

输出结果:

  1. h
  2. e
  3. l
  4. l
  5. o
  6.  
  7. k
  8. n
  9. i
  10. g
  11. h
  12. t
  13.  
  14. 6
  15. 6
  16. 6

练习2

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

图示:

代码:

  1. msg = 'hello knight 666'
  2. count = 0
  3. while True:
  4. print(msg[count])
  5. count += 1
  6. if count == len(msg):
  7. break

输出结果:

  1. h
  2. e
  3. l
  4. l
  5. o
  6.  
  7. k
  8. n
  9. i
  10. g
  11. h
  12. t
  13.  
  14. 6
  15. 6
  16. 6

练习3

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

代码:

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

输出结果:

  1. hello knight

练习4

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

代码:

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

输出结果:

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

练习5

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

图示:

代码:

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

练习6

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

图示:

代码:

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

练习7

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

图示:

代码1:

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

代码2:

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

练习8

题目:

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

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

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

图示:

代码:

  1. user_info = ['knight','zhuozi','tangbao']
  2. tag = True
  3. while tag:
  4. username = input('Please enter username:').strip()
  5. password = input('Please enter password:')
  6. if not username or not password:
  7. print('Your account or password is blank, please re-enter')
  8. continue
  9. month = input('Please enter the month:').strip()
  10. salary = input('Please enter the salary:').strip()
  11. if not month.isdigit() or not salary.isdigit():
  12. print('The month or salary you enter must be an integer.')
  13. if username == 'root' and password == '123456':
  14. print('Login successfully!')
  15. while tag:
  16. print('请选择以下功能\n1、查询用户功能\n2、查询总工资功能\n3、退出')
  17. cmd = input('Please select function:').strip()
  18. if cmd == '1':
  19. user = input('Please enter username:').strip()
  20. if user == 'knight':
  21. print('super user')
  22. elif user == 'tangbao' or user == 'zhuozi':
  23. print('normal user')
  24. else:
  25. print('known user')
  26. elif cmd =='2':
  27. print('Your total salary is %s'%(int(month)*int(salary)))
  28. elif cmd =='3':
  29. print('Goodbye!')
  30. tag = False
  31. else:
  32. print('Invalid command,please try again!')
  33. else:
  34. 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. node Buffer.byteLength()

    Buffer.byteLength(string[, encoding]) string {String} | {Buffer} | {TypedArray} | {DataView} | {Arra ...

  2. 杭电 1009 FatMouse' Trade (贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  3. NioEventLoopGroup中的nThreads和executor

    NioEventLoopGroup只传入nThreads即可,创建nThreads个NioEventLoop,boss为NioEventLoop注册建立的channel时,使用默认的ThreadPer ...

  4. 创建私有 Gems 源

    1.安装依赖 yum install gem -y gem install builder   2.安装.配置nginx的文件列表 添加/etc/nginx/default.d/mirrors.con ...

  5. JavaEE JDBC 读写LOB大对象

    JDBC 读写LOB大对象 @author ixenos LOB 除了数字.字符串和日期之外,许多数据库还可以存储大对象,例如图片或其他数据, 在SQL中,二进制(字节型)大对象称为BLOB,字符型大 ...

  6. SQL Server-索引管理

    http://www.2cto.com/database/201305/207508.html SQL Server-索引管理   一.显示索引信息 在建立索引后,可以对表索引信息进行查询. (1)在 ...

  7. 【bzoj3505】[Cqoi2014]数三角形

    [bzoj3505][Cqoi2014]数三角形 2014年5月15日3,5230 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4×4的网格上的一个三角 ...

  8. node框架express里面静态文件中间件express.static,根据路径名查找文件

    - 是express框架下的一个方法,可以根据请求路径名查找某个文件下文件名字和路径名相同的文件 - 3.X里面有20多个中间件,但是在4.X里面 只保留了express.static - 语法 ex ...

  9. JPA中映射关系详细说明(一对多,多对一,一对一、多对多)、@JoinColumn、mappedBy说明

    JPA中的映射关系 jpa中维护one to one ,one to many, many to one ,many to many 四种映射关系. 在每个关系中,双方中的一方在其表中拥有连接列.那么 ...

  10. Java Web 总结

    Java Servlet 总结 Servlet 简介 Servlet 是什么? 运行在Web服务器上的应用程序,作为浏览器和服务器之间的中间层. 与CGI功能类似,优点在于 性能更好 在Web服务器的 ...