导航菜单
首页 >  » 正文

Python练习题 python 题目

Python练习题

首先 range是reversed word 在这里你可以理解为python保留词汇 也就是说你给一个变量赋值时 不能命名其为range 因为你下载的python里已经有了range的用法和相关操作规则 wiki中的定义为a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label (也就是前面我所解释的 当然 wiki更权威 相信你也能读懂 )

其他的reserved word 可以随便举例 比如 random in for print 等等 都可以

python 题目

#-*- coding:utf-8 -*-
def binary_search(slist,goal):
二分查找 slist为要查找的列表,goal为目标

Return middle为目标的下标
low=0
high=len(slist)-1
while(low<=high):
middle=(high-low)/2 low
if(slist[middle]==goal):
return middle
elif(slist[middle]>goal):
high=middle-1
elif(slist[middle] low=middle 1
return -1

哪里有带答案的 Python 习题吗


哪里有带答案的 Python 习题
1,使用getopt。getopt()优化当前的功能函数:
[html]
#!/usr/bin/python
# -*- coding: utf-8 -*-
#coding=utf-8
import os,sys
import getopt
print sys.argv
CDROW=/home/zhouqian/test
def cdWalker(CDROW,cdfile):
result=[]
for root,dirs,files in os.walk(CDROW):
result.append("%s %s %s" %(root,dirs,files))
print root
open(cdfile,w).write( .join(result))

def usage():
print pycdc 使用方式:
python cdays-3-exercise-1.py -d cdc -k 中国火
#检索cdc中有没有中国火字样的目录,

try:
opts,args=getopt.getopt(sys.argv[1:],hd:e:k:)
except getopt.GetoptError:
usage()
sys.exit()

python选择题/简答题

1. True的选项是A
2. True的选项是A
3. 输出是16 range(2,10)>2,3,4,5,6,7,8,9 循环了3次,X分别为2,3,4
4. 输出的结果是(-2,3,5)
5. people = [{name: Mary, height: 160},{name: Isla, height: 80},

{name: Sam}]
height=0
n=0
for i in range(len(people)):
     if isinstance((people[i].get(height)),int):
        n=n 1
        height=people[i].get(height)  height      
else:
     print(人员的平均身高为%s% (height/n))

相关推荐: