经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Python » 查看文章
Python全栈学习_day002作业
来源:cnblogs  作者:BlameKidd  时间:2018/10/23 9:24:14  对本文有异议

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

  1. 1True
  2. 2False

 

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

  1. 18
  2. 24

 

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

  1. 16
  2. 23
  3. 3False    # 注意这个
  4. 43
  5. 5True
  6. 6True
  7. 70
  8. 83
  9. 90
  10. 102

 

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

  1. while 条件:
  2. 循环体

 

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

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

  1. f = 66
  2. while 1:
  3. num = int(input('请输入一个数字:'))
  4. if f == num:
  5. print('猜测正确')
  6. break
  7. elif f > num:
  8. print('小了')
  9. else:
  10. print('大了')

 

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

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

  1. f = 66
  2. count = 0
  3. while 1:
  4. num = int(input('请输入一个数字:'))
  5. if count == 2:
  6. print('太笨了你')
  7. break
  8. if f == num:
  9. print('猜测正确')
  10. break
  11. elif f > num:
  12. print('小了')
  13. count += 1
  14. else:
  15. print('大了')
  16. count += 1

 

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

  1. num = 1
  2. while num < 11:
  3. print(num)
  4. num += 1

 

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

  1. 方法一:
  2. flag = True
  3. count = 1
  4. sum = 0
  5. while flag:
  6. sum += count
  7. count += 1
  8. if count > 100:
  9. flag = False
  10. print(sum)
  11. 方法二:
  12. num = 1
  13. sum = 0
  14. while num < 101:
  15. sum += num
  16. num += 1
  17. print(sum)
  18. 方法三:
  19. sum = 0
  20. for i in range(101):
  21. sum += i
  22. print(sum)

 

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

  1. 方法一:
  2. for i in range(1,101, 2):
  3. print(i)
  4. 方法二:
  5. count = 1
  6. while count < 101:
  7. if count % 2 == 1:
  8. print(count)
  9. count += 2
  10. else:
  11. count += 2

 

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

  1. 方法一:
  2. for i in range(2,101, 2):
  3. print(i)
  4. 方法二:
  5. count = 2
  6. while count < 101:
  7. if count % 2 == 0:
  8. print(count)
  9. count += 2
  10. else:
  11. count += 2

 

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

  1. count = 1
  2. sum = 0
  3. while count < 100:
  4. sum += (-1)**(count-1) * count
  5. count += 1
  6. print(sum)

 

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

  1. name = 'BlameKidd'
  2. pwd = '123123'
  3. count = 2
  4. while count >= 0:
  5. name_input = input('请输入用户名:')
  6. pwd_input = input('请输入密码:')
  7. if name == name_input and pwd == pwd_input:
  8. print('登录成功')
  9. else:
  10. print('用户名或密码错误,还剩%s次输入机会' % (count))
  11. count -= 1

 

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

  1. ASCII码:
  2. 英文:8
  3. Unicode
  4. 英文:32
  5. 中文:32
  6. UTF-8
  7. 英文:8
  8. 欧洲文字:16
  9. 中文:24

 

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

  1. 8 == 1个字节

 

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

  1. UTF-89个字节
  2. GBK6个字节

 

 

下周一默写代码:

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

 

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

 

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号