《python核心编程第二版》第2章习题
2-1 略
2-1 略
2-2
(a)打印 结果是9
(b)9
(c)一样
(d)略
(e)略
2-3 略
2-4 (a)
# /usr/bin/python
raw_input()
(b)
# /usr/bin/python
str1 = raw_input()
print int(str1)
2-5
(a)
# /usr/bin/python
i=1
while i < 11:
print i
i = i+1
(b)
# /usr/bin/python
for i in range(1,11):
print i
2-6
# /usr/bin/python
# coding:utf8
num = raw_input()
if num >0:
print "正数"
elif num <0:
print "负数"
else:
print "0"
2-7
# /usr/bin/python
# coding:utf8
flag = 1 while flag != '0':
flag = raw_input()
print flag
2-8
# /usr/bin/python
# coding:utf8
list1 = [1,2,9,3,4]
print sum(list1) for i in range(0,5):
list1[i] = int(raw_input())
print sum(list1)
2-9
# /usr/bin/python
# coding:utf8
list1 = [1,2,9,3,4]
print float(sum(list1))/5
2-10
# /usr/bin/python
# coding:utf8
flag =1
while flag!=0:
i = int(raw_input())
if i>1 and i <100:
flag = 0
else:
print "重新输入"
2-11
# /usr/bin/python
# coding:utf8
i = '1'
while i!='X':
list1 = [1,3,4,5,7]
i = raw_input()
if i == '1':
print sum(list1)
elif i == '2':
print float(sum(list1))/5
2-12
(a)['__builtins__', '__doc__', '__file__', '__name__', '__package__']
(b)<built-in function dir>
(c)报错
(d)略
2-13
(a)['__displayhook__', '__doc__', '__egginsert', '__excepthook__', '__name__', '__package__', '__plen', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']
(b)
darwin
2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
(c)略
2-14
print -2*4 + (3**2)
2-15
# /usr/bin/python
# coding:utf8
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
list1 = [a,b,c]
print sorted(list1)
print sorted(list1,reverse=True)
2-16
略
《python核心编程第二版》第2章习题的更多相关文章
- Python核心编程(第二版)PDF
Python核心编程(第二版) 目录 第1部分 Python核心第1章 欢迎来到Python世界1.1 什么是Python1.2 起源1.3 特点1.3.1 高级1.3.2 面向对象1.3.3 可升级 ...
- 拒绝从入门到放弃_《Python 核心编程 (第二版)》必读目录
目录 目录 关于这本书 必看知识点 最后 关于这本书 <Python 核心编程 (第二版)>是一本 Python 编程的入门书,分为 Python 核心(其实并不核心,应该叫基础) 和 高 ...
- python核心编程第二版笔记
python核心编程第二版笔记由网友提供:open168 python核心编程--笔记(很详细,建议收藏) 解释器options:1.1 –d 提供调试输出1.2 –O 生成优化的字节码(生成 ...
- Python核心编程第二版(中文).pdf 目录整理
python核心编程目录 Chapter1:欢迎来到python世界!-页码:7 1.1什么是python 1.2起源 :罗萨姆1989底创建python 1.3特点 1.3.1高级 1.3.2面向 ...
- 《python核心编程第二版》第8章习题
8–1. 条件语句. 请看下边的代码 # statement Aif x > 0:# statement Bpasselif x < 0:# statement Cpasselse:# s ...
- 《python核心编程第二版》第1章练习
1–1. 安装 Python.请检查 Python 是否已经安装到你的系统上,如果没有,请下载并 安装它 略 1–2. 执行 Python.有多少种运行 Python 的不同方法?你喜欢哪一种?为什 ...
- python 核心编程第二版 课后习题 第11章
11-3 函数.在这个练习中,我们将实现 max()和 min()内建函数. (a) 写分别带两个元素返回一个较大和较小元素,简单的 max2()核 min2()函数.他们应该可以用任意的 pytho ...
- 《python核心编程第二版》第7章习题
7–1. 字典方法.哪个字典方法可以用来把两个字典合并到一起? 答:dict1.update(dict2) 7–2. 字典的键.我们知道字典的值可以是任意的Python 对象,那字典的键又如何呢?请试 ...
- 《python核心编程第二版》第5章习题
5-1 整形 讲讲 Python 普通整型和长整型的区别 答:普通整型 32位,长整数类型能表达的 数值仅仅与你的机器支持的(虚拟)内存大小有关 5-2 运算符(a) 写一个函数,计算并返回两个数的乘 ...
- 《python核心编程第二版》第4章习题
4–1. Python 对象.与所有 Python 对象有关的三个属性是什么?请简单的
随机推荐
- 【洛谷P1774】最接近神的人
最接近神的人_NOI导刊2010提高(02) 用类似于桶的方法,树状数组记录原序列的某位置之前已经插入了多少个数, 插入时树状数组单点加1即可 先排一遍序,从大到小插入所有数在原序列的位置, 统计每次 ...
- java基础知识一览(二)
一.java基础知识 1.一个文件中只能有一个public的类,因为他的类名要求和文件名相同. 2.classpath变量可以设置其它目录下的类. 例如:类文件所在目录是:F:\Javajdk,那么没 ...
- 02_Linux 终端命令格式
01. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相应功能的英文单词或单词的缩写 [-options]:选项,可用来对命令进行控制,也 ...
- React Router 4 的使用(2)
Route Rendering Props 对于给定的路由如何渲染组件,有三种选项:component.render.children.你可以查看 <Route> 的文档来获取更多的信息, ...
- Java基础——线程复习总结
线程 T ...
- JavaScript基础-----数组(Array)
1.JavaScript 中创建数组的方法: (1).使用Array构造函数: var arr = new Array(); //创建一个空数组 var arr = new Array(5); //传 ...
- JSONP 通用函数封装
function jsonp({url, params, callback}) { return new Promise((resolve, reject) => { let script = ...
- C++定义一个简单的Computer类
/*定义一个简单的Computer类 有数据成员芯片(cpu).内存(ram).光驱(cdrom)等等, 有两个公有成员函数run.stop.cpu为CPU类的一个对象, ram为RAM类的一个对象, ...
- MySQL 字符串函数:字符串截取
1.left(name,4)截取左边的4个字符 列: ,) 年 结果:2018 2.right(name,2)截取右边的2个字符 ,) 月份 结果:09 3.SUBSTRING(name,5,3) 截 ...
- linux链路聚合
配置聚合连接(网卡绑定,链路聚合): eth0 ================>>虚拟网卡team eth1 配置聚合连接 [root@Centos7-Server ~]# nmcli ...