ROSLIND网站中的python village中的答案

网站:[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”不是等同的,加上引号代表的是字符串,而没有引号的则是整数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值