Python全栈学习_day002作业

时间:2023-03-09 08:30:55
Python全栈学习_day002作业

Day2作业及默写

1、判断下列逻辑语句的True,False.

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

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

)True
)False

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

1),8 or 3 and 4 or 2 and 0 or 9 and 7

2),0 or 2 and 3 and 4 or 6 and 0 or 3


3、下列结果是什么?

1)、6 or 2 > 1

2)、3 or 2 > 1

3)、0 or 5 < 4

4)、5 < 4 or 3

5)、2 > 1 or 6

6)、3 and 2 > 1

7)、0 and 3 > 1

8)、2 > 1 and 3

9)、3 > 1 and 0

10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2



)False    # 注意这个

)True
)True



4、while循环语句基本结构?

while 条件:
循环体

5、利用if语句写出猜大小的游戏:

设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。

f =
while :
num = int(input('请输入一个数字:'))
if f == num:
print('猜测正确')
break
elif f > num:
print('小了')
else:
print('大了')

6、在5题的基础上进行升级:

给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。

f =
count =
while :
num = int(input('请输入一个数字:'))
if count == :
print('太笨了你')
break
if f == num:
print('猜测正确')
break
elif f > num:
print('小了')
count +=
else:
print('大了')
count +=

7、使用while循环输出 1 2 3 4 5 6 8 9 10

count =
while count < :
count +=
if count == :
continue
print(count)

8、求1-100的所有数的和(三种方法)

方法一:
flag = True
count =
sum =
while flag:
sum += count
count +=
if count > :
flag = False
print(sum)
方法二:
num =
sum =
while num < :
sum += num
num +=
print(sum)
方法三:
sum =
for i in range():
sum += i
print(sum)

9、输出 1-100 内的所有奇数(两种方法)

方法一:
for i in range(,, ):
print(i)
方法二:
count =
while count < :
if count % == :
print(count)
count +=
else:
count +=

10、输出 1-100 内的所有偶数(两种方法)

方法一:
for i in range(,, ):
print(i)
方法二:
count =
while count < :
if count % == :
print(count)
count +=
else:
count +=

11、求1-2+3-4+5 ... 99的所有数的和

count =
sum =
while count < :
sum += (-)**(count-) * count
count +=
print(sum)

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

name = 'BlameKidd'
pwd = ''
count =
while count >= :
name_input = input('请输入用户名:')
pwd_input = input('请输入密码:')
if name == name_input and pwd == pwd_input:
print('登录成功')
else:
print('用户名或密码错误,还剩%s次输入机会' % (count))
count -=

13、简述ASCII、Unicode、utf-8编码关系?

ASCII码:
英文:8位
Unicode:
英文:32位
中文:32位
UTF-:
英文:8位
欧洲文字:16位
中文:24位

14、简述位和字节的关系?

8位 == 1个字节

15、“⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?

UTF-:9个字节
GBK:6个字节

下周一默写代码:

Bit,Bytes,KB,MB,GB,TB之间的转换关系。

Python全栈学习_day002作业

Unicode,utf-8,GBK,每个编码英文,中文,分别用几个字节表示。

Python全栈学习_day002作业