python核心编程 第二版 第二章 习题
来源:互联网 发布:淘宝客二合一链接转换 编辑:程序博客网 时间:2024/06/02 11:18
初学python,将自己练习的代码发在这存着,若有人看到,希望不吝赐教。~
-----------------------------------------------------------------------------------------------------------------------
2-5a:
i = 0while i <= 10:print ii = i + 1
2-5b:
for i in range(0,11):print i
2-6:
a = 100print "Is a greater than 0?"print a > 0# ------------------------------------------------- #input = int(raw_input('Input your number >> '))if input > 0:print "Input is Positive."elif input < 0:print "Input is Negative."elif input == 0:print "Input is Zero."
2-7:
input = str(raw_input("print your string >> "))i = 0len = len(input)while i < len:print input[i],i = i + 1printfor char in input:print char,
2-8:
a_list = [1, 2, 3, 4, 5]a_tuple = [11.2, 2.2, 0.33, 1.44, 25.5]b = sum(a_list) / float(len(a_list))c = sum(a_tuple) / float(len(a_tuple))print bprint c
2-9:
a_list = [1, 2, 3, 4, 5]a_tuple = [11.2, 2.2, 0.33, 1.44, 25.5]b = sum(a_list) / float(len(a_list))c = sum(a_tuple) / float(len(a_tuple))print bprint c
2-10:
while True:input = int(raw_input("Print your number >> "))if 1 <= input <= 100:print "All right."breakelse:print "ERROR!"print "Choose another one."
2-11:
a_list = []i = 0while i < 5:input = int(raw_input('Print your number >> '))a_list.append(input)i += 1#------------------------------------#len = len(a_list)sum = sum(a_list)average = sum / float(len)#------------------------------------#while True:print '''(s)um the number(a)verage the number (q)uit the manu '''# breakchoice = str(raw_input('your choice is >> '))if choice in 'saq':if choice == 's':print "The sum is ", sumelif choice == 'a':print "The average is ", averageelse:print "Thanks for using."print "Bye!"breakelse:print "I don't know."print "Try again!"
2-15:(这段是从网上摘录的,自己写起来毫无头绪。。)
SortList = [0, 1, 2]for i in range(0,3): print 'Please input the No.', i+1, 'number to be sort' SortList[i] = float(raw_input())print SortList if SortList[0] < SortList[1]: i = SortList[0] SortList[0] = SortList[1] SortList[1] = iif SortList[0] < SortList[2]: i = SortList[0] SortList[0] = SortList[2] SortList[2] = i if SortList[1] < SortList[2]: i = SortList[1] SortList[1] = SortList[2] SortList[2] = i print SortList
0 0
- Python核心编程 第二版 第二章 部分习题解答
- python核心编程 第二版 第二章 习题
- python核心编程第二版第二章习题
- <python 核心编程第二版课后习题>第二章
- python核心编程第二章习题
- Python核心编程第二章课后习题
- 《Python核心编程》第二章习题解答
- Python核心编程第二章习题
- 《python核心编程第二版》第三章习题
- Python核心编程(第二版) 第五章 课后习题(1)
- python核心编程(第二版)习题_第三章
- python核心编程 第二版 第五章 习题
- <Python核心编程 第二版> 第四章习题
- 《python 核心编程第二版第六章》习题
- 《python 核心编程第二版第六章》习题补充
- 《python核心编程第二版》第六章 习题补充
- 《python核心编程第二版第六章》习题 补
- 《python 核心编程第二版第7章》习题
- 八大排序算法之快速排序
- 类加载机制-类加载机制
- 从程序员到CTO的Java技术路线图
- redis入门及java操作
- leetcode——169——Majority Element
- python核心编程 第二版 第二章 习题
- 循序渐进之Maven(3) - 第一个Web项目
- java系统高并发解决方案之图片服务器分离
- 健康知识_图标滑动动态添加
- Android---加载图片 解决图片过大导致的内存溢出问题
- 输入数据得平均值
- 纳税服务投诉受理模块中投诉与回复中的级联查询等细节
- leatcode 13,Roman to Integer
- javaEE 部门树状结构显示以及要注意的问题