python核心编程第2章课后题答案(第二版36页)
来源:互联网 发布:mac java 安全设置 编辑:程序博客网 时间:2024/04/28 04:49
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))
0 0
- python核心编程第2章课后题答案(第二版36页)
- python核心编程第3章课后题答案(第二版55页)
- python核心编程第4章课后题答案(第二版75页)
- python核心编程第二版 第8章课后题
- python核心编程第5章课后题答案
- Python学习之《python核心编程》 第二章课后答案
- Python学习之《python核心编程》 第二章课后答案
- Python核心编程(第二版)第六章课后习题答案
- python核心编程第二章课后题答案(python3.5+)
- 《Python核心编程》中文第二版课后练习2.21答案
- 《Python核心编程》中文第二版课后练习3.8答案
- python核心编程-第12章课后练习答案
- python核心编程-第7章课后习题答案
- python核心编程-第8章课后习题答案
- <python 核心编程第二版课后习题>第二章
- Python核心编程第二章课后习题
- 《python核心编程第二版》第二章练习答案解析
- Python核心编程(第二版) 第五章 课后习题(1)
- str() 和repr()的区别
- enumerate()函数
- leetcode 刷起!!!!
- win10和ubuntu双系统下卸载ubuntu
- python文件输入和输出
- python核心编程第2章课后题答案(第二版36页)
- python核心编程第3章课后题答案(第二版55页)
- 快速定位注册表收藏夹分支
- python核心编程第4章课后题答案(第二版75页)
- python math模块
- python random模块
- python decimal和fractions模块
- python核心编程第5章课后题答案
- 格式化操作符( % )