网站:[http://rosalind.info/problems/list-view/]
一个关于生物信息学基础Python的网站,再次我对于其中关于python village中的问题提供一些解决方
案。
**
第一点 Python中的幂运算
**
# python中的幂运算
a=3
b=5
print(a**2 + b**2)
第二点 字符串的切片
#字符串的切片
string="HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntputHumptyDumptyinhisplaceagain"
new_str=string[0:12]
print(new_str)
new_str1=new_str.split("y")
第三点 计算100-200的奇整数和
result=0
#计算100到200的奇整数之和
for i in range(200):
if i >= 100:
if i%2 == 1:
result=result+i
print(result)
第四点 提取文件中的偶数行
path="C:/Users/Administrator/Desktop/code/rosalind/提取偶数行.txt"
file=open(path)
i=0
world_list=[]
for line in file.readlines():
str=line
i += 1
if i % 2 == 0:
print(str)
world_list.append(str)
print(world_list)
file=open("file_name.txt",'w')
for item in world_list:
file.write(item)
file.close()
第五点 统计每个单词的次数
# 统计每个单词出现的次数
word="We tried list and we tried dicts also we tried Zen"
word=word.split()
print(word)
for item in word:
count= word.count(item)
print("%s 出现了%s次" % (item,count) )
Python中学习注意的问题:0和“0”不是等同的,加上引号代表的是字符串,而没有引号的则是整数。