老男孩Python九期全栈学习笔记3

时间:2023-03-09 09:44:16
老男孩Python九期全栈学习笔记3

day3

1、上周五内容回顾

  格式化输出:%s  %d  

  %%:输出%

  编码:

    ASCII码只能显示英文、数字和特殊字符。

    Unicode:万国码,最开始使用16位表示一个字符,中文不够,后来使用4个字节表示一个字符

    utf-8:Unicode的升级版,使用3个字节表示中文

    gbk:在ASCII码基础上中国人发明的,与中文有对应关系,内部包含了ASCII码

  

2、作业讲解

1、判断下列逻辑语句的真假

(1)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6      #False

(2)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6        #True

(3)1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8 and 4 > 6 or 3 < 2    #False

2、求出下列逻辑语句的值

(1)8 or 3 and 4 or 2 and 0 or 9 and 7      #8

(2)0 or 2 and 3 and 4 or 6 and 0 or 3      #4

(3)5 and 9 or 10 and 2 or 3 and 5 or 4 or 5    #9

3、下列结果是什么?

(1)6 or 2 > 1        #6

(2)3 or 2 > 1        #3

(3)0 or 5 < 4        #False

(4)5 < 4 or 3        #3

(5)2 > 1 or 6        #True

(6)3 and 2 > 1        #True

(7)0 and 3 > 1        #0

(8)2 > 1 and 3        #3

(9)3 > 1 and 0        #0

(10)3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2      #2

4、简述变量名命名规范

5、name = input('>>>')name变量是什么数据类型

6、if条件语句的基本结构

7、while循环语句基本结构

8、写代码:计算1+2+3+...+99中除了88外所有数的总和。

 count = 0
sum = 0 while count < 99:
count += 1
if count == 88:
continue
sum += count
print(count)
print(sum)

ps:写代码:计算1-2+3...+99中除了88外所有数的总和。

 count = 0
sum = 0 while count < 99:
count += 1
if abs(count) == 88:
continue
if count % 2 == 1:
sum += count
else:
sum -= count
print(sum)

9、用户登录(三次输入机会 )且每次输入错误时显示剩余次数(提示:使用字符串格式化)

 i = 3
while i:
urn = input('Please input username:')
pwd = input('Please input password:')
if urn == 'Francis周':
if pwd == 'Francis8848':
print('Welcome!')
break
else:
i -= 1
if i == 0:
print('Sorry!please try 24 Hours later!')
else:
print('The password is not true.You have %d chance left.Try again!' %(i))
else:
print('The username is not true!')

10、简述ASCII,Unicode,utf-8编码关系

11、简述位和字节的关系

12、“老男孩”使用UTF-8编码占用几个字节?使用GBK编码占用几个字节?

13、制作趣味模板程序需求:等待用户输入名字、地点、爱好,根据用户的名字和爱好进行任意实现

14、等待用户输入内容,检测用户输入内容中是否含有敏感字符?如果存在敏感字符提示“存在敏感字符请重新输入”,并允许用户重新输入并打印。敏感字符:“小 皮球”,“大菠萝”

15、单行注释及多行注释

16、简述你所知道的python2与python3的区别

17、看代码书写结果

a = 1 > 2 or 4 < 7 and 8 == 8

print(a)

key:a = True

18、continue与break的区别

19、看代码书写结果

a = 12 & 127

print(a)

key:12

3、int

4、bool

5、str