python核心编程第2章课后题答案(第二版36页)
2-5 Loops and Numbers
a) i = 0
while i <11:
print i
i += 1
b) for i in range(0,11):
print i
2-6 Conditionals
n =int( raw_input('enter a number:'))
if n < 0:
print 'negative'
elif n > 0:
print 'positive'
else:
print 'zero'
2-7 Loops and strings
s = raw_input('enter a string:')
for each_char in s:
print each_char
or
for i in range(len(s)):
print i,s[i]
or
i = 0
slen = len(s)
while i < slen:
print i,s[i]
i +=1
or
for i,x in enumerate(s):
print i,x
2-8 Loops and operators
subtot = 0
for i in range(5):
subtot + = int(raw_input('enter a number:'))
print subtot
or
print sum(int(raw_input('enter a mumber:')) for i in range (5))
python核心编程第2章课后题答案(第二版36页)的更多相关文章
- python核心编程第4章课后题答案(第二版75页)
4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...
- python核心编程第5章课后题答案
5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the ...
- python核心编程第3章课后题答案(第二版55页)
3-4Statements Ues ; 3-5Statements Use\(unless part of a comma-separated sequence in which case \ is ...
- python 核心编程第六章课后题自己做的答案
6–6. 字符串.创建一个 string.strip()的替代函数:接受一个字符串,去掉它前面和后面的 空格(如果使用 string.*strip()函数那本练习就没有意义了) 'Take a str ...
- Python核心编程2第一章课后练习
1-1 在windows下的安装方法在网上下载python2.7直接安装到C盘1)在系统变量中找到path. 2)编辑path值,添加你安装的python路径,C:\Python27. 3)检验pyt ...
- 【7】python核心编程 第十一章-函数和函数式编程
1.*函数(与方法)装饰器 装饰器背后的主要动机源自python 面向对象编程.装饰器是在函数调用之上的修饰.这些修饰 仅是当声明一个函数或者方法的时候,才会应用的额外调用. 装饰器的语法以@开头,接 ...
- python核心编程第六章练习6-8
6-8.列表.给出一个整型值,返回代表该值得英文,比如输入89会返回“eight-nine”.附加题:能够返回符合英文语法规律的新式,比如输入89会返回“eighty-nine”.本练习中的值假定在0 ...
- 【1】python核心编程 第三章
1.继续( \ ) 有两种例外情况一个语句不使用反斜线也可以跨行.在使用闭合操作符时,单一语句可以跨多行,例如:在含有小括号.中括号.花括号时可以多行书写.另外就是三引号包括下的字符串也可以跨行书写 ...
- python核心编程-第三章-习题
1.这是python的语言特性,python先创建对象,在给变量赋值时,不需要定义变量的名称和类型,它实际是用变量引用对象.变量类型在给变量赋值时自动声明 2.原因类似变量无须声明类型 3.pytho ...
随机推荐
- centos6.x 配置bond
centos6.x 配置bond centos6.x 配置bond1 物理网卡配置2 bond0网卡配置3 查看bond0网卡状态 摘要: centos6.x下使用双网卡配置bond0, centos ...
- mysql字段详细
http://www.runoob.com/mysql/mysql-data-types.html
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- leetcode 21.Merge Two Sorted Lists ,java
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- Nginx 改变错误日志打印级别
Nginx 改变错误日志打印级别 user root;worker_processes 2; worker_rlimit_nofile 10240;error_log logs/nginx_err ...
- 【转】 Pro Android学习笔记(九七):BroadcastReceiver(1):基础小例子
目录(?)[-] 基础小例子 发送Broadcast intent 运行情况 应用间的广播 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog ...
- An internal error occurred during: "Map/Reducelocation status updater".java.lang.NullPointerException
当我们运行wordcount代码时,出现报错,如下所示: An internal error occurred during: "Map/Reducelocation status upda ...
- thinkphp中的session的使用和理解!
session的作用:session可以长时间的保存数据,不丢失. session的常用于: 1.登录,保存登录信息 2.保存购物车信息 3.保存验证码信息 定义session常量 define('W ...
- MFC 控件使用汇总
一.动态创建button CButton *button=new CButton; button->Create(_T(,,,),);//最后一个是ID BEGIN_MESSAGE_MAP(CM ...
- keil:C语言里面调用汇编程序
C语言直观,汇编效率高,C里面嵌入汇编是很好的选择. 路径大概如图: mian.c是我的C语言程序,Func.s是汇编程序. 主要是Init_1这个函数的实现在汇编文件里面,使用汇编实现的. 首先在C ...