Python程序设计习题与答案.pdfVIP

  • 294
  • 0
  • 约4.67万字
  • 约 40页
  • 2021-05-27 发布于江苏
  • 举报
文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 . 《Python 程序设计》习题与参考答案 第 1 章 基础知识 1.1 简单说明如何选择正确的 Python 版本。 答: 在选择 Python 的时候,一定要先考虑清楚自己学习 Python 的目的是什么,打算做哪方 面的开发, 有哪些扩展库可用, 这些扩展库最高支持哪个版本的 Python ,是 Python 2.x 还是 Python 3.x ,最高支持到 Python ,再做出自己的选择,这样才能事半功倍,而不至于把大 量时间浪费在 Python 的反复安装和卸载上。同时还应该注意,当更新的 Python 版本推出之 后,不要急于更新, 而是应该等确定自己所必须使用的扩展库也推出了较新版本之后再进行 更新。 尽管如此, Python 3 毕竟是大势所趋, 如果您暂时还没想到要做什么行业领域的应用开 发,或者仅仅是为了尝试一种新的、好玩的语言,那么请毫不犹豫地选择 Python 3.x 系列的 最高版本(目前是 Python 1.2 为什么说 Python 采用的是基于值的内存管理模式? 答: Python 采用的是基于值的内存管理方式,如果为不同变量赋值相同值,则在内存中只 有一份该值,多个变量指向同一块内存地址,例如下面的代码。 x = 3 id(x) y = 3 id(y) y = 5 id(y) id(x) 1.3 在 Python 中导入模块中的对象有哪几种方式? 答:常用的有三种方式,分别为 import 模块名 [as 别名 ] from 模块名 import 对象名 [ as 别名 ] from math import * 1文档收集于互联网,如有不妥请联系删除 . 文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 . 1.4 使用 pip 命令安装 numpy 、scipy 模块。 答:在命令提示符环境下执行下面的命令: pip install numpy pip install scipy 1.5 编写程序,用户输入一个三位以上的整数,输出其百位以上的数字。例如用户输入 1234,则程序输出 12。(提示:使用整除运算。 ) 答: 1)Python x = input(Please input an integer of more than 3 digits:) try: x = int(x) x = x//100 if x == 0: print(You must input an integer of more than 3 digits.) else: print(x) except BaseException: print(You must input an integer.) 2 )Python import types x = input(Please input an integer of more than 3 digits:) if type(x) != types.IntType: print You must input an integer. elif len(str(x)) != 4: print You must input an integer of more than 3 digits. else: print x//100

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档