CheckIO Mine

it2026-08-15  8

CheckIO GITHUB

题目1:Fizz Buzz题目2:Cut Sentence题目3:Best Stock题目4:Bigger Together题目5:Binary Count题目6:Achilles and the Tortoise题目7:Caesar Cipher (decryptor)题目8:Caesar Cipher (encryptor)题目9:Moore Neighbourhood题目10:Fast Train题目11:Find Enemy题目12:题目13:题目14:题目15:题目16:题目17:题目18:题目19:题目20:题目21:

题目1:Fizz Buzz

def checkio(number: int) -> str: if not number%15: return 'Fizz Buzz' if not number%3: return 'Fizz' if not number%5: return 'Buzz' return f'{number}'

题目2:Cut Sentence

def cut_sentence(line, length): if len(line) <= length: return line line1 = line[:length] a = [x for x in line1.split(' ') if x in line.split(' ')] return ' '.join(a)+'...'

题目3:Best Stock

def best_stock(data: dict) -> str: x_max = max(data.values()) return [x[0] for x in data.items() if x_max in x][0]

其他人的答案:max中的key为一函数

def best_stock(a): return max(a, key=a.get)

题目4:Bigger Together

未解锁

题目5:Binary Count

题目6:Achilles and the Tortoise

未解锁

题目7:Caesar Cipher (decryptor)

import re def to_decrypt(cryptotext, delta): cryptotext = re.sub('[^a-zA-Z ]+', '',cryptotext) sum = '' for x in cryptotext: if x == ' ': sum += x continue if ord(x) + delta < ord('a'): sum += chr(ord(x) + delta + ord('z') - ord('a') +1) continue if ord(x) + delta > ord('z'): sum += chr(ord(x) + delta - ord('z') + ord('a') -1) continue sum += chr(ord(x) + delta) return sum

其他人的答案

def to_decrypt(cryptotext, delta): text = '' for i in cryptotext: if i.isalpha() or i == ' ': text += i return ''.join([chr((ord(ch) - 97 + delta) % 26 + 97) if ch != ' ' else ch for ch in text])

题目8:Caesar Cipher (encryptor)

def to_encrypt(text, delta): return ''.join([chr((ord(x) - ord('a') +delta) % 26 + ord('a')) if x != ' ' else x for x in text])

题目9:Moore Neighbourhood

from itertools import product def count_neighbours(grid, row, col): count = 0 for x,y in product([-1,0,1],[-1,0,1]): if (x,y) == (0,0): continue if row+x<0 or col+y<0: continue try: if grid[row+x][col+y] == 1: count += 1 except: print(x, y) pass return count

题目10:Fast Train

未解锁

题目11:Find Enemy

题目12:

题目13:

题目14:

题目15:

题目16:

题目17:

题目18:

题目19:

题目20:

题目21:

最新回复(0)