Challenge Checkio(python)—初尝python练习网站

时间:2021-07-29 12:11:11

最近在找点python语言练习的网站,发现这个网站不错

http://www.checkio.org/

页面设计的也比较漂亮,比较适合学习python的语法知识。
不过注册这个网站 开始就得解决一个python问题,不过很简单。
Challenge Checkio(python)—初尝python练习网站

 #python3.3 is inside
def checkio(els):
return els if checkio([1, 2, 3, 4, 5, 6]) == 6:
print('Done!')

对上面的代码 修改checkio中的函数 函数使得输出的是列表里面前上个数的和。

 def checkio(els):
return els[0]+els[1]+els[2] #后面也看见人家写 return sum(els[0:3])
if checkio([1, 2, 3, 4, 5, 6]) == 6:
print('Done!')

简单修改一个就够了 然后直接registration.
Challenge Checkio(python)—初尝python练习网站
进去以后刷python题目 通关 有点植物大战僵尸的感觉 .
第一个题目 就是Non-unique Elements.
Challenge Checkio(python)—初尝python练习网站

code :

temp=[]
a=len(data)
def checkio(data):
for n in range(a):
if data.count(n)>1:
temp.append(data[n])
data =temp
return data

后面看到 creative 排名第一的写法 更有创意

def checkio(data):
return([x for x in data if data.count(x)>1])

这样写的话更简洁,用的是 列表解析 的方法 可以在一行中用一个for循环将所有的值加入到列表中..