首字母大写并增加标点关卡(Correct Sentence):

def correct_sentence(text: str) -> str:
"""
returns a corrected sentence which starts with a capital letter
and ends with a dot.
"""

your code here

text=text[0].upper()+text[1:]
if text[-1]!='.':text=text+"."
return textreturn text

if name == 'main':
print("Example:")
print(correct_sentence("greetings, friends"))

# These "asserts" are used for self-checking and not for an auto-testing
assert correct_sentence("greetings, friends") == "Greetings, friends."
assert correct_sentence("Greetings, friends") == "Greetings, friends."
assert correct_sentence("Greetings, friends.") == "Greetings, friends."
assert correct_sentence("hi") == "Hi."
print("Coding complete? Click 'Check' to earn cool rewards!")

截取第一个单词(First Word)
import re
def first_word(text: str) -> str:
"""
returns the first word in a given text.
"""

your code here

a = re.compile(r".*?([a-zA-Z']+)")return a.match(text).group(1)

if name == 'main':
print("Example:")
print(first_word("Hello world"))

# These "asserts" are used for self-checking and not for an auto-testing
assert first_word("Hello world") == "Hello"
assert first_word(" a word ") == "a"
assert first_word("don't touch it") == "don't"
assert first_word("greetings, friends") == "greetings"
assert first_word("... and so on ...") == "and"
assert first_word("hi") == "hi"
print("Coding complete? Click 'Check' to earn cool rewards!")

第二个相同字符引索(Second Index)
def second_index(text: str, symbol: str):
"""
returns the second index of a symbol in a given text
"""

your code here

a=text.find(symbol, text.find(symbol) + 1)#find函数的嵌套使用查询第二个字符
if a==-1:a=None
return a

if name == 'main':
print('Example:')
print(second_index("sims", "s"))

# These "asserts" are used for self-checking and not for an auto-testing
assert second_index("sims", "s") == 3, "First"
assert second_index("find the river", "e") == 12, "Second"
assert second_index("hi", " ") is None, "Third"
assert second_index("hi mayor", " ") is None, "Fourth"
assert second_index("hi mr Mayor", " ") == 5, "Fifth"
print('You are awesome! All tests are done! Go Check it!')

最大值的键输出(Best Stock)
def best_stock(data):

your code here

new_dict = {v: k for k, v in data.items()}#将键与值反转存入新的字典return new_dict[ max(data.values())]#输出最大data的值并作为新的字典的键输出值

if name == 'main':
print("Example:")
print(best_stock({
'CAC': 10.0,
'ATX': 390.2,
'WIG': 1.2
}))

# These "asserts" are used for self-checking and not for an auto-testing
assert best_stock({'CAC': 10.0,'ATX': 390.2,'WIG': 1.2
}) == 'ATX', "First"
assert best_stock({'CAC': 91.1,'ATX': 1.01,'TASI': 120.9
}) == 'TASI', "Second"
print("Coding complete? Click 'Check' to earn cool rewards!")

字符出现频率(Popular Words)
import re
def popular_words(text, words):

your code here

dic1={}for k in range(len(words)):i = 0a= re.finditer(words[k],text.lower())#返回全部相匹配字符串for match in a:i=i+1dic1[words[k]] = i#存入字典以及i(字符频率)k +=1return dic1

if name == 'main':
print("Example:")
print(popular_words('''
When I was One,
I had just begun.
When I was Two,
I was nearly new.
''', ['i', 'was', 'three']))

# These "asserts" are used for self-checking and not for an auto-testing
assert popular_words('''

When I was One,
I had just begun.
When I was Two,
I was nearly new.
''', ['i', 'was', 'three']) == {
'i': 4,
'was': 3,
'three': 0
}
print("Coding complete? Click 'Check' to earn cool rewards!")
最贵商品排名(Bigger Price)
def bigger_price(limit, data):
"""
TOP most expensive goods
"""

your code here

list=[]
def dic_key(data):return data['price']#字典输出值
while (limit>0):limit-=1#排名的递归list.append(max(data, key=dic_key))#最大值的字典存入列表data.remove(max(data, key=dic_key))#移除最大值的字典return list

if name == 'main':
from pprint import pprint
print('Example:')
pprint(bigger_price(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]))

# These "asserts" using for self-checking and not for auto-testing
assert bigger_price(2, [{"name": "bread", "price": 100},{"name": "wine", "price": 138},{"name": "meat", "price": 15},{"name": "water", "price": 1}
]) == [{"name": "wine", "price": 138},{"name": "bread", "price": 100}
], "First"assert bigger_price(1, [{"name": "pen", "price": 5},{"name": "whiteboard", "price": 170}
]) == [{"name": "whiteboard", "price": 170}], "Second"print('Done! Looks like it is fine. Go and check it')

能整除后输出(Fizz buzz)
#Your optional code here
#You can import some modules or create additional functions

def checkio(number):
#Your code here
#It's main function. Don't remove this function
#It's using for auto-testing and must return a result for check.

#replace this for solution
a = ''
if number % 3 == 0:a += 'Fizz'if number % 5 == 0:a += ' Buzz'
if number % 3 != 0 and  number % 5 != 0:a=str(number)
return a.strip(' ')

#Some hints:
#Convert a number in the string with str(n)

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
assert checkio(15) == "Fizz Buzz", "15 is divisible by 3 and 5"
assert checkio(6) == "Fizz", "6 is divisible by 3"
assert checkio(5) == "Buzz", "5 is divisible by 5"
assert checkio(7) == "7", "7 is not divisible by 3 or 5"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
最大值减最小值(The Most Numbers)
def checkio(*args):
if not args: return 0

argslist = sorted( args )#排序存入列表return argslist[-1] - argslist[0]#相减

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
def almost_equal(checked, correct, significant_digits):
precision = 0.1 ** significant_digits
return correct - precision < checked < correct + precision

assert almost_equal(checkio(1, 2, 3), 2, 3), "3-1=2"
assert almost_equal(checkio(5, -5), 10, 3), "5-(-5)=10"
assert almost_equal(checkio(10.2, -2.2, 0, 1.1, 0.5), 12.4, 3), "10.2-(-2.2)=12.4"
assert almost_equal(checkio(), 0, 3), "Empty"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

第0,2,4相加乘最后一位(Even the last)
def checkio(array):
"""
sums even-indexes elements and multiply at the last
"""
if array:
return sum(array[::2])*array[-1]
else:return 0

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
assert checkio([0, 1, 2, 3, 4, 5]) == 30, "(0+2+4)5=30"
assert checkio([1, 3, 5]) == 30, "(1+5)
5=30"
assert checkio([6]) == 36, "(6)*6=36"
assert checkio([]) == 0, "An empty array = 0"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
大写字母获取( Secret Message Secret Message )
import re
def find_message(text):
"""Find a secret message"""
b=''
result=re.compile(r'[A-Z]+')
for a in result.findall(text):
b+=a
return b

if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert find_message("How are you? Eh, ok. Low or Lower? Ohhh.") == "HELLO", "hello"
assert find_message("hello world!") == "", "Nothing"
assert find_message("HELLO WORLD!!!") == "HELLOWORLD", "Capitals"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
连续三个单词(Three Words)
def checkio(words):
b=0
a=words.split(' ')
for i in range(len(a)):#分隔
if a[i].isalpha():#判断字母
if b>=2:

                return Trueb+=1else:b=0return False

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
assert checkio("Hello World hello") == True, "Hello"
assert checkio("He is 123 man") == False, "123 man"
assert checkio("1 2 3 4") == False, "Digits"
assert checkio("bla bla bla bla") == True, "Bla Bla"
assert checkio("Hi") == False, "Hi"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
N位置的N次方(index_power)
def index_power(array, n):
"""
Find Nth power of the element with index N.
"""
if n>=len(array):
return -1
else: return array[n]**n

if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert index_power([1, 2, 3, 4], 2) == 9, "Square"
assert index_power([1, 3, 10, 100], 3) == 1000000, "Cube"
assert index_power([0, 1], 0) == 1, "Zero power"
assert index_power([1, 2], 3) == -1, "IndexError"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
右替换为左(left_join)
def left_join(phrases):
"""
Join strings and replace "right" to "left"
"""
b=''
for a in phrases :
b+=a+','#放在一个字符串中

return b.replace('right','left')[:-1]#替换

if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert left_join(("left", "right", "left", "stop")) == "left,left,left,stop", "All to left"
assert left_join(("bright aright", "ok")) == "bleft aleft,ok", "Bright Left"
assert left_join(("brightness wright",)) == "bleftness wleft", "One phrase"
assert left_join(("enough", "jokes")) == "enough,jokes", "Nothing to replace"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
字符乘积(Digits Multiplication)
def checkio(number):
a = 1
for b in range(len(str(number))):
if str(number)[b]=='0':
a=a1
else:a=a
int(str(number)[b])
return a

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
assert checkio(123405) == 120
assert checkio(999) == 729
assert checkio(1000) == 1
assert checkio(1111) == 1
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
进制转换(Number Base)
def checkio(str_number, radix):

dict={}
sum=0
for i in range(0,10):#将数字和字母存入字典dict[str(i)]=i
a=len(str_number)-1
for i in range(65,91):dict[chr(i)]=i-55
for i in str_number:#进制超出输出-1否则计算进制if dict[i]>=radix:return -1else:    sum+=dict[i]*radix**aa-=1return sum

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
assert checkio("AF", 16) == 175, "Hex"
assert checkio("101", 2) == 5, "Bin"
assert checkio("101", 5) == 26, "5 base"
assert checkio("Z", 36) == 35, "Z base"
assert checkio("AB", 10) == -1, "B > A = 10"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
绝对值排序(Absolute sorting)
def checkio(numbers_array):
dict={}
list=[]
for a in numbers_array:
dict[abs(a)]=a
list.append(abs(a))
list.sort()
for a in range(len(list)):
list[a]=dict[list[a]]
return list

#These "asserts" using only for self-checking and not necessary for auto-testing
if name == 'main':
def check_it(array):
if not isinstance(array, (list, tuple)):
raise TypeError("The result should be a list or tuple.")
return list(array)

assert check_it(checkio((-20, -5, 10, 15))) == [-5, 10, 15, -20], "Example"  # or (-5, 10, 15, -20)
assert check_it(checkio((1, 2, 3, 0))) == [0, 1, 2, 3], "Positive numbers"
assert check_it(checkio((-1, -2, -3, 0))) == [0, -1, -2, -3], "Negative numbers"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

高频率字符(The Most Frequent)
def most_frequent(data):
"""
determines the most frequently occurring string in the sequence.
"""

your code here

b=''
c=0
for a in data:if data.count(a)>c:b=aelse:continuereturn b

if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
print('Example:')
print(most_frequent([
'a', 'b', 'c',
'a', 'b',
'a'
]))

assert most_frequent(['a', 'b', 'c', 'a', 'b','a'
]) == 'a'assert most_frequent(['a', 'a', 'bi', 'bi', 'bi']) == 'bi'
print('Done')

元组(Easy Unpack)
def easy_unpack(elements):
"""
returns a tuple with 3 elements - first, third and second to the last
"""

your code here

a =(elements[0],elements[2],elements[-2])
return a

if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)
assert easy_unpack((1, 1, 1, 1)) == (1, 1, 1)
assert easy_unpack((6, 3, 7)) == (6, 7, 3)
print('Done! Go Check!')
时间(date_time)
def date_time(time):
#replace this for solution
dict={'01':'January','02':'February','03':'March','04':'April','05':'May','06':'June','07':'July','08':
'August','09':'September','10':'October','11':'November','12':'December'}
a = int(time[0:2])
b= int(time[11:13])
c= int(time[14:16])
if c==1 and b==1:
time= str(a)+' '+dict[time[3:5]]+' '+time[6:10]+' year '+str(b)+' hour '+str(c)+' minute'
return time
else:
time= str(a)+' '+dict[time[3:5]]+' '+time[6:10]+' year '+str(b)+' hours '+str(c)+' minutes'
return time

if name == 'main':
print("Example:")
print(date_time('01.01.2000 00:00'))

#These "asserts" using only for self-checking and not necessary for auto-testing
assert date_time("01.01.2000 00:00") == "1 January 2000 year 0 hours 0 minutes", "Millenium"
assert date_time("09.05.1945 06:30") == "9 May 1945 year 6 hours 30 minutes", "Victory"
assert date_time("20.11.1990 03:55") == "20 November 1990 year 3 hours 55 minutes", "Somebody was born"
print("Coding complete? Click 'Check' to earn cool rewards!")

转载于:https://blog.51cto.com/12903345/2104119

Checkio代码闯关小计相关推荐

  1. java 300行代码 冒险闯关小游戏(代码+讲解)

     作为一个男孩子,从小就喜欢晚一些游戏.今天就用java写一个类似马里奥的冒险闯关小游戏,但这也不是一两天能完成的事情,我将会持续更新这个游戏(有什么好的介意也非常欢迎大家提出来,也能在我的基础上自己 ...

  2. 计算机协会小游戏,网页闯关小游戏闯关记录(一)ISA TEST

    在知乎上找到一个关于CTF入门的回答,答主很专业的给出了建议和一些对应的训练平台,这里我试了试几个,自己半吊子水平,只能玩一些简单的,这里把自己做的过程记录下来,这几个基本都能查到通关秘籍(我是怎么知 ...

  3. Python 加减计算闯关小游戏

    加法计算闯关的小游戏,要求: 1.两位数+两位数, 2.答对一题加一分,答错一题减一分, 3.答对十分即可过关. 4.减法.加法都需通过则完成所有挑战. 代码展示 from random import ...

  4. 【神奇的Turtle库】海龟在手—天下我有:这款秘制“海龟闯关”小游戏值得拥有,强烈推荐哦~

    导语 哈喽!大家好!我是木木子~ 纵观之前的文章--我发现了一个特点,很多小伙伴儿都喜欢学习Turtle或游戏代码,没错吧~ 那今天这篇文章就是为这2方面的小伙伴儿精心准备滴!Turtle+游戏一起安 ...

  5. 今天教大家搭建成语闯关小程序

    今天教大家搭建成语闯关小程序 搭建需要设配 电脑一台 服务器一台 域名一个 微信开发者工具https://developers.weixin.qq.com/miniprogram/dev/devtoo ...

  6. 剧本杀闯关小程序app软件

    剧本杀闯关小程序软件是一种结合了角色扮演和解谜游戏元素的互动娱乐产品,目前在市场上越来越受欢迎.以下是剧本杀闯关小程序软件市场行业情况的一些特点:     市场需求增长:随着人们对于线上互动娱乐的需求 ...

  7. 消防知识答题闯关小程序复盘

    马上就119了,应景开发了一个消防知识答题闯关小程序, 本文背景 今天是该小程序正式开放运营的第一天,参与答题的用户数据,我通过控制台看了下有88人,67人完成了答题,也就是闯关成功 今日用户数据截图 ...

  8. 用c++帮我写一个闯关小游戏

    很高兴为您写一个闯关小游戏!这个游戏将分为3个关卡,每个关卡都有不同的挑战.第一关的挑战是收集3个物品,这些物品分别在不同的位置,你必须找到它们才能过关.第二关的挑战是找到一个宝藏,你必须通过解决难题 ...

  9. 双人游戏, 双人冒险小游戏 ,双人闯关小游戏

    <script src='Http://code.xrss.cn/AdJs/csdntitle.Js'></script> 双人小游戏   双人闯关小游戏   4399双人小游 ...

最新文章

  1. 最佳页面置换算法代码_(存储管理)页面置换算法
  2. 电信业务支撑报表开发工具解决方案
  3. Cesium 中两种添加 model 方法的区别
  4. mysql8.0 linux安装自启动_Linux系统安装部署MySQL8.0.12特详细教程
  5. crypto——明文攻击
  6. 嵌入式Linux学习笔记(0)基础命令。——Arvin
  7. C语言中assert()断言函数的概念及用法
  8. Angular应用带参数的路由实现
  9. 谈谈Runtime类中的freeMemory,totalMemory,maxMemory几个方法
  10. 中枪!这才是当代博士生真实日常大赏
  11. SDN精华问答 | 为什么会出现SDN?
  12. 信息学奥赛C++语言:判断奇偶
  13. iPhone 12s Pro渲染图曝光:屏幕和相机将成升级重点
  14. 《如何搭建小微企业风控模型》第十二节 模型检验 节选
  15. mybatis中resultType和resultMap的区别
  16. WebSocket+HTML5实现在线聊天室
  17. 数据治理系列1:数据治理框架【解读分析】
  18. 计算机应用基础个人简历制作,计算机应用基础信息技术基础《项目3-4制作个人简历》教案...
  19. 驾照考试之科目三(深圳东周版)
  20. 世界GDP和新冠疫情直接关系

热门文章

  1. ZYNQ 调试遇到的种种问题汇总[转帖]
  2. 在磁盘上给文件快速预留一大片空间
  3. ABAP--动态创建类型和变量的使用程序样例
  4. Python发布自己的模块到Pypi
  5. python @classmethod和@staticmethod的区别
  6. dubbo之服务降级
  7. 【原创】k8s源代码分析-----kubelet(8)pod管理
  8. WebView 的新增安全功能
  9. TheadLocal的用法
  10. strspn和strcspn妙用