《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 对象有关的三个属性是什么?请简单的
随机推荐
- MVC学习二:Controller和View关系
控制器(Controller)主要是定义方法和加载视图(View) 1.控制器中的Action方法返回值的类型ActionResult,string 2.控制器中Action方法接收浏览器参数方式: ...
- 【luogu P2194 HXY烧情侣】 题解
题目链接:https://www.luogu.org/problemnew/show/P2194 第一问:缩点并且统计其强连通分量里的最小耗费.把所有强连通分量的最小耗费加起来. 第二问:统计在每个强 ...
- socket 代码实例
1. TCP SOCKET 客户端: #!/usr/bin/env python # -*-coding:utf-8 -*- import socket HOST = 'localhost' PO ...
- Spring-boot官方案例分析之log4j
Spring-boot官方案例分析之log4j 运行单元测试分析: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfigur ...
- mix-blend-mode 混合模式 background-blend-mode 背景混合模式 isolation:isolate 隔离
css3 mix-blend-mode 混合模式 该属性不仅可以作用于HTML,还可以作用于SVG 兼容性: IE 8~11 Edge 12~14 Firefox 41~47 chrome 45~51 ...
- 『ACM C++』 PTA 天梯赛练习集L1 | 016-017
今天开了两个大会,时间都给占掉了,就刷了两道题~ 明天加油!!! ------------------------------------------------L1-016------------- ...
- C++创建一个名为Ellipse的椭圆类--练习
题目描述: /*设计名为Ellipse的椭圆类*/ /* 其属性为外接矩形的左上角与右下角两个点的坐标,并能计算出椭圆的面积,并测试该类. */ 代码如下: #include<iostream& ...
- substr在oracle和mysql中的应用和区别
Oracle: 书写格式: (1)Select substr(字段名(string) , 起始位置(int) , 截取长度(int)) 示例: selectsubstr('123456',0,3)a ...
- 你的sql查询为什么这么慢?
做后台开发的程序猿通常需要写各种各样的sql,可很多时候写出来的sql虽然能满足功能性需求,性能上却不尽人意.如果业务复杂,表结构和索引设计又不合理的话,写出来的sql执行时间可能会达到几十甚至上百秒 ...
- Firewalld共享上网及本地yum仓库搭建
1.firewalld共享上网 1.服务端操作(有外网的服务器) 1.开启防火墙并加入开机自启动 [root@zeq ~]# systemctl start firewalld [root@zeq ~ ...