Python语言程序设计(美-梁勇)第4章习题解答(英文_第1页
Python语言程序设计(美-梁勇)第4章习题解答(英文_第2页
Python语言程序设计(美-梁勇)第4章习题解答(英文_第3页
Python语言程序设计(美-梁勇)第4章习题解答(英文_第4页
Python语言程序设计(美-梁勇)第4章习题解答(英文_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter 4 Selections1., , = 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.random.randrange(10, 20) or random.randint(10, 19)5.random.randrange(10, 50 + 1) or random.randint(10, 50)6.random.randrange(0, 2) or random.randint

2、(0, 1) 7.if y 0: x = 18.if score 90: pay *= 1.039.if score 90: pay *= 1.03else: pay *= 1.0110.If number is 30, (a) displays 30 is even30 is odd(b) displays 30 is evenIf number is 35, (a) displays 35 is odd(b) displays 35 is odd11.Note: else matches the second if clause. The output is “x is 3” if x =

3、 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.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.13. Consider score is 90, what will be the

4、grade? The conditions are tested in the wrong orders.14. (A) and (C) are equivalent. (B) and (D) are incorrectly indented.15.newLine = (count % 10 = 0)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

5、is even(b) displays14 is evenFor number is 15, (a) displays:15 is multiple of 5(b) displays15 is multiple of 5For number is 30, (a) displays:30 is even30 is multiple of 5(b) displays30 is even18.Yes19.This program will have a runtime error, because tax will not be created.20.(true) and (3 4)Falsenot

6、(x 0) and (x 0)False(x 0) or (x = 0) or (x 1) and (x 1) and (x 100) or (x = y = 0 Falsex = 0Truex!= y = 5True(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

7、) is True(x y or y z) is Truenot (x y) is False(x y z) is Truenot (x y 13 and age 50 or height 160.29.weight 50 and height 160.30.(weight 50 or height 160) and not (weight 50 and height 160) 31.Sorted32. ticketPrice = 20 if (ages = 16) else 10print(count, end = n if count % 10 = 0 else )33.A:if x 10: score = 3 * scaleelse: score = 4 * scaleB:if income 10000: tax = income * 0.2else: tax = income * 0.17 + 1000C:if number % 3 = 0: print(i)else: print(j) 34.The precedence order of the Boolean operators

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论