1到4题比较简单,这里省略

5题6题代码

def main():prompt = input("Enter the name: ").lower().split()P = ""num = 0for ch in prompt:P = P + chfor p in P:num = num + ord(p) - 96print(num)main()

7题8题答案

def main():prompt = input("Enter the word: ").split()s = []key = int(input("Key: "))for p in prompt:q = []for i in range(len(p)):if ord(p[i]) + key <= ord("z"):q.append(chr(ord(p[i]) + key))else:q.append(chr(ord(p[i]) + key - 26))h = "".join(q)s.append(h)for ch in s:print(ch, end=" ")
main()

9题答案

def main():prompt=input("Enter the word: ").split()i = 0for p in prompt:i=i+1print("The number of the words is {0}.".format(i))
main()

10题答案

def main():A = input("Please enter the words: ").split()n = 0totalLength = 0for a in A:n = n + 1totalLength = totalLength+len(a)avg = j / iprint("The average length is {0:0.3f}.".format(avg))
main()

11题答案

def main():print("This program illlustrates a chaotic function")x1, x2 = eval(input("Enter two numbers between 0 and 1 seperated by a comma: "))n = int(input("Enter the change times: "))print("|{0:<7}|{1:<10}|{2:<9}|".format("index", x1, x2))print("_" * 30)for i in range(n):x1 = 3.9 * x1 * (1 - x1)x2 = 3.9 * x2 * (1 - x2)print("|{0:<7}|{1:<10.6f}|{2:<9.6f}|".format(i + 1, x1, x2))main()

12题答案

def main():principal = eval(input("Enter the initial principal: "))apr = float(input("Enter the annual interest rate: "))years = int(input("Enter the number of years: "))print()print("Year     Value")print("-------------------")for i in range(years + 1):print("{0:<8}${1:.2f}".format(i, principal))principal = principal * (1 + apr)main()

13题,略

14题答案

def main():filename = input("Enter the filename: ")infile = open(filename, 'r')chars = infile.read()words = chars.split()lines = chars.split("\n")infile.close()print("Lines:", len(lines))print("Words:", len(words))print("Characters:", len(chars))main()

15题答案

def mark(window, name, point, pos, m):a = 2Name = Text(Point(2, m+a - pos), name)Mark = Rectangle(Point(5, m +0.45 +a- pos), Point(5 + point / 10, m-0.45+a - pos))Mark.setWidth(2)Mark.setFill(color_rgb(144,144,255))Text(Point(18, m +a- pos), str(point)).draw(window)Name.draw(window)Mark.draw(window)def main():filename = input("Enter the name of the file: ")infile = open(filename, "r", encoding="utf-8")data = infile.read()data1 = data.split("\n")m = int(data1[0])win = GraphWin("grades", 55*(m+2), 55*(m+2))win.setCoords(0, 0, 20, m+3)win.setBackground("white")for i in range(1,len(data1)):data2 = data1[i].split()name,point = data2[0],float(data2[1])mark(win, name, point, i, m)print("Click to quit.")infile.close()win.getMouse()win.close()main()

16题答案

def main():filename = input("Enter the name of the file:")infile = open(filename, "r")inf = infile.read()win = GraphWin("Students' Grade", 300, 200)win.setCoords(0, 0, 18, 12)win.setBackground(color_rgb(10, 155, 20))for i in range(11):p = str(i)n = inf.count(p)drb(win, p, n, i)win.getMouse()win.close()infile.close()def drb(window, p, n, i):u = i*1.58Text(Point(u + 1,0.5),p).draw(window)Text(Point(u + 1,1.5 + n),str(n)).draw(window)bar = Rectangle(Point(u + 0.54,1),Point(u + 1.46,1 + n))bar.setFill(color_rgb(34, 68, 255))bar.setOutline("red")bar.draw(window)main()

《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 5 章 编程练习答案相关推荐

  1. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 9 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 9 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 计算机可以生成真正的随机数. Python 的 r ...

  2. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 5 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 5 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 Python 字符串字面量总是用双引号括起来. 字 ...

  3. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 7 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 7 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 一个简单的判断可以用一个if 语句来实现. 在Py ...

  4. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 1 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 1 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 1.计算机科学是计算机的研究. 2.CPU 是计算 ...

  5. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 6 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 6 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 程序员很少定义自己的函数. 函数只能在程序中的一个 ...

  6. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 10 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 10 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 通过调用构造方法创建新对象. 位于对象中的函数称 ...

  7. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 8 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 8 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 Python 的 while 实现了一个有限循环. ...

  8. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 3 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 3 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 1.由计算机存储和操作的信息称为数据. 2.由于浮 ...

  9. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 2 章 答案

    <Python程序设计(第3版)>[美] 约翰·策勒(John Zelle) 第 2 章 答案 答案仅供参考,若有错误欢迎指正 判断对错 1.编写程序的好方法是立即键入一些代码,然后调试它 ...

  10. python程序设计第3版课后答案_python程序设计第三版课后答案

    python程序设计第三版课后答案 更多相关问题 该图中XOY为地轴,MN为赤道,EF.E′F′为回归线,ST.S′T′为极圈.读图,回答下列问题.(10分)(1)目前黄赤交角在图上 (共10分,每空 ...

最新文章

  1. 嵌入式linux应用程序升级,基于嵌入式Linux平台的应用升级机制的研究与设计
  2. 创建第一个 local network(I) - 每天5分钟玩转 OpenStack(80)
  3. 数组的遍历你都会用了,那Promise版本的呢
  4. 量子计算机是否存在相对论,潘建伟团队再登Science:寻找广义相对论与量子力学的桥梁...
  5. Linux. C语言中else,2. if/else语句
  6. 单处理器系统的进程调度_第三章:进程与线程
  7. 业内最大规模多标签图像数据集开源 | GitHub资源
  8. charles抓包工具的使用:手机抓包设置和安装证书
  9. 推行ISO9000的作用及相关知识
  10. inventor牙距_滚子链计算基础知识 | Inventor 2018 | Autodesk Knowledge Network
  11. php对接工行sdk,工商银行-银企直连签约流程
  12. 双光耦开关电源电路图_几种常见开关电源电路图
  13. linux视频播放器安装程序,新手求助自带视频播放器安装问题
  14. Python 函数的使用和内嵌函数
  15. 游戏外挂怎么来的?十年经验的老程序员道出了这些不为人知的秘密
  16. 微信小程序实现生成海报并且保存本地
  17. 淘宝客网站应该怎么优化?
  18. 外盘国际期货招商:每日港股市场要闻
  19. 6-4 使用函数求素数和 (20 分)
  20. Hadoop Yarn ResourceManager启动失败

热门文章

  1. 人到中年再无奈,也要有这3种“毛病”,余生漫长,越超脱越舒服
  2. 计算室内甲醛释放量的经验公式
  3. 数据结构初阶:八大排序
  4. Elasticsearch5.3.1 IK分词,同义词/联想搜索设置
  5. 宋有陈抟擅矩文, 内方外圆有如神。 逐浪字库技更精, 数字出版工匠魂
  6. linux怎么设置桌面朝向,Android判断相机图片朝向
  7. Camera/Lens流程(一)——点亮
  8. 制作Surfer自定义图例
  9. YOLOv5的参数与性能指标
  10. 论文阅读:Poselet-Based Contextual Rescoring for Human Pose Estimation