自己在pychekio上的练习之home

本文介绍了PyCheckio平台上的几个游戏挑战,包括判断棋局胜负、评估棋子安全性和寻找最大最小值。游戏涉及逻辑推理和算法设计,如计算棋盘上保护的兵卒数量和使用内置函数max/min进行比较。
摘要由CSDN通过智能技术生成

1.House  Password--------------------------------------------- ----------------------------------------

Input: A password as a string.

Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.

Example:

checkio('A1213pokl') == False
checkio('bAse730onE') == True
checkio('asasasasasasasaas') == False
checkio('QWERTYqwerty') == False
checkio('123456123456') == False
checkio('QwErTy911poqqqq') == True

def checkio(data):
    if len(data)>=10:
        if not(data.isdigit() or data.isalpha() or data.islower() or data.isupper()):
            return True
    return False

2.The Most Wanted Letter-------------------------------------------- ---------------------------------------

If you have two or more letters with the same frequency, then return the letter which comes first in the latin alphabet. For example -- "one" contains "o", "n", "e" only once for each, thus we choose "e".

Input: A text for analysis as a string.

Output: The most frequent letter in lower case as a string.

Example:

checkio("Hello World!") == "l"
checkio("How do you do?") == "o"
checkio("One") == "e"
checkio("Oops!") == "o"
checkio("AAaooo!!!!") == "a"
checkio("abe") == "a"

def checkio(text):
    lower_text = text.lower()
    appear_time = {}
    for each in lower_text:
        if each.islower():
            if each not in appear_time:
                appear_time[each] = 0
            else:
                appear_time[each] += 1
    array = list(appear_time.items()) 
    array.sort(key=lambda x:x[0])
    array.sort(key=lambda x:x[1], reverse=True)
    return array[0][0]

3.Non-unique Elements-------------------------------------------- -------------------------------------

You are given a non-empty list of integers (X). For this task, you should return a list consisting of only the non-unique elements in this list. To do so you will need to remove all unique elements (elements which are contained in a given list only once). When solving this task, do not change the order of the list. Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].

non-unique-elements

Input: A list of integers.

Output: The list of integers.

Example:

checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3]
checkio([1, 2, 3, 4, 5]) == []
checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5]
checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9]

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

    #replace this for solution
    list2=[]
    for num in data:
        count=data.count(num)
        if count>=2:        
            list2.append(num)
        else:pass
    return list2

4.Mokey Typing---------------------------------------------- ------------------------------------

You are given some text potentially including sensible words. You should count how many words are included in the given text. A word should be whole and may be a part of other word. Text letter case does not matter. Words are given in lowercase and don't repeat. If a word appears several times in the text, it should be counted only once.

For example, text - "How aresjfhdskfhskd you?", words - ("how", "are", "you", "hello"). The result will be 3.

Input: Two arguments. A text as a string (unicode for py2) and words as a set of strings (unicode for py2).

Output: The number of words in the text as an integer.

Example:

count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3
count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2
count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
            {"sum", "hamlet", "infinity", "anything"}) == 1

def count_words(text, words):
    text=text.lower()
    count=0
    for word in words:
        if word in text:
            count+=1
    return count
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值