云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Python语言程序设计(美-梁勇)第4章习题解答(英文)

Python语言程序设计(美-梁勇)第4章习题解答(英文)

  • 62 次阅读
  • 3 次下载
  • 2025/6/4 9:32:52

Chapter 4 Selections

1. 2. Yes. i becomes 1, j becomes 0, b1 becomes True, and b2 becomes Flase.

3. random.randrange(0, 20) or random.randint(0, 19)

4. 5. 6. 7. 8.

if score > 90: pay *= 1.03

<, <=, ==, !=, >, >=

random.randrange(10, 20) or random.randint(10, 19) random.randrange(10, 50 + 1) or random.randint(10, 50) random.randrange(0, 2) or random.randint(0, 1)

if y > 0: x = 1

9.

if score > 90: pay *= 1.03 else:

pay *= 1.01

10.

If number is 30, (a) displays 30 is even 30 is odd

(b) displays 30 is even

If number is 35, (a) displays 35 is odd

(b) displays

35 is odd 11. Note: else matches the second if clause. The output is “x is 3” if x = 3 and y = 2. The output is “z is 7” if if x = 3 and y = 4. No output if if x = 2 and y = 2.

True x > 2 False y > 2 True z = x + y print(\ False print(\

12. Note: else matches the first if clause. The output is “x is 2” if x = 2 and y = 4. No output if if x = 3 and y = 2. The output is “z is 6” if if x = 3 and y = 3.

True x > 2 False y > 2 True z = x + y print(\ False print(\ 13.

Consider score is 90, what will be the grade? The conditions are tested in the wrong orders.

14.

(A) and (C) are equivalent. (B) and (D) are incorrectly indented.

newLine = (count % 10 == 0)

15.

16.

Both are correct. (B) is better. Both conditions in (A) are tested. In (B) the condition is

tested only once.

17.

For number is 14, (a) displays: 14 is even

(b) displays 14 is even

For number is 15, (a) displays: 15 is multiple of 5

(b) displays

15 is multiple of 5

For number is 30, (a) displays: 30 is even

30 is multiple of 5

(b) displays 30 is even

18.

Yes

19. 20.

This program will have a runtime error, because tax will not be created. (true) and (3 > 4) False

not(x > 0) and (x > 0)

False

(x > 0) or (x < 0) True

(x != 0) or (x == 0) True

(x >= 0) or (x < 0) True

(x != 1) == not (x == 1)

True

21. (x > 1) and (x < 100)

22. ((x > 1) and (x < 100)) or (x < 0) 23.

x >= y >= 0 False

x <= y >= 0 True

x != y == 5 True

(x != 0) or (x == 0) True

24.

Yes

25.

If ch is 'A', the expression is true; If ch is 'p', the expression is false; If ch is 'E', the expression is true; If ch is '5', the expression is false;

26.

(x < y and y < z) is True (x < y or y < z) is True not (x < y) is False (x < y < z) is True

not (x < y < z) is False

27. age > 13 and age < 18 28.

weight > 50 or height > 160.

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Chapter 4 Selections 1. 2. Yes. i becomes 1, j becomes 0, b1 becomes True, and b2 becomes Flase. 3. random.randrange(0, 20) or random.randint(0, 19) 4. 5. 6. 7. 8. if score > 90: pay *= 1.03 <, , >= random.randrange(10, 20) or random.randint(10, 19) random.randrange(10, 50 + 1) or random.randint(10, 5

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com