【Python爬虫】-测试题
2017-07-08 本文已影响407人
DoctorLDQ
一.作业内容:测试题
二.作业代码:
a=10
b=3
print("a+b=",a+b)
print("a-b=",a-b)
print("a*b",a*b)
print("b/a=",b/a)
print("10的3次幂=",pow(10,3))
print("a/b",a/b)
print("10%3=",10%3)
sum=0
for x in range(1,101):
sum+=x
print(sum)
sum=0
num=[x for x in range(1,101) if x%2==0]
for n in num:
sum+=n
print(sum)
id='d55ea4b3e190'
sum=0
for x in id:
if x.isdigit():
sum+=int(x)
else:
pass
print(sum)
id='d55ea4b3e190'
a=list(id)
a.sort()
print(a)
str='0cd768f4b1a1dac0c512e452726361d9'
str_list=list(str)
# str_tuple=tuple(str)
str_trans=[]
i=0
j=0
if(len(str_list)%2!=0):
str_list.pop()
else:pass
while(i<(len(str_list)-2)):
str_trans.append(str_list[i]+str_list[i+1])
i=i+1
str_tuple=tuple(str_trans)
print(str_trans)
print(str_tuple)
dic={}
for i in range(1,4):
dic[i-1]=str(i)
print(dic)
dict_date = {"Led Zeppelin":1969,
"Led Zeppelin II": 1969,
"Led Zeppelin III": 1970,
"Led Zeppelin IV": 1971,
"Houses of the Holy":1973,
"Physical Graffiti": 1975,
"Presence":1976,
"In Through the Out Door":1979,
"Coda":1982}
for k,v in dict_date.items():
if(v>=1970 & v<1976):
print(k)
else:pass
def swap(x,y):
x,y=y,x
return (x,y)
a=1
b=2
print("a={} b={} ".format(a,b))
(a,b)=swap(a,b)
print('交换后 a={} b={}'.format(a,b))
#print("通过range(10)产生一个[0,1,2,3,4,5,6,7,8,9],通过for循环遍历,并且判断是否为偶数,如果是偶数,则添加到list_a")
list_a = [i for i in range (10) if i % 2]
print(list_a)
dict_date = {"Led Zeppelin":1969,
"Led Zeppelin II": 1969,
"Led Zeppelin III": 1970,
"Led Zeppelin IV": 1971,
"Houses of the Holy":1973,
}
val_list=[]
dic={}
for k,v in dict_date.items():
if v in val_list:
pass
else:
val_list.append(v)
dic[v]=[k]
print(dic)
import os
import time
num=range(1,13)
i=0
f=open("test.html","a+")
while(i<=12):
i=i+1
print("**********第%d题**************" %i )
os.system("python {}.py".format(i))
if(i==11):
print("存储为value list未完成!")
time.sleep(5)
break
f.close()
三.学习总结:文件操作陌生,字符串的一些操作不够熟练。