大宮盆栽デイズ - Omiya Bonsai Days -

冗談めかす埼玉のファインマン

2019-10-07から1日間の記事一覧

@CheckiO@Easy Unpack

def easy_unpack(elements: tuple) -> tuple: """ returns a tuple with 3 elements - first, third and second to the last """ # your code here elem_first = elements[0] elem_third = elements[2] elem_last = elements[-2] t = elem_first, elem_third…

@CheckiO@Secret Message

def find_message(text: str) -> str: """Find a secret message""" import re s = re.findall('[A-Z]', text) s = ','.join(s) text = s.replace(',','') return str(text) if __name__ == '__main__': print('Example:') print(find_message("How are you?…

@CheckiO@Index Power

def index_power(array: list, n: int) -> int: """ Find Nth power of the element with index N. """ length = len(array) if n+1 > length: return -1 data = array[n] data = data ** n return int(data) if __name__ == '__main__': print('Example:') …

@CheckiO@Fizz Buzz

# Your optional code here # You can import some modules or create additional functions def checkio(number: int) -> str: # Your code here # It's main function. Don't remove this function # It's using for auto-testing and must return a resul…

@CheckiO@Three Words

def checkio(words: str) -> bool: list_words = words.split(' ') length = len(list_words) if length < 3: return False count = 0 for w in list_words: if w.isalpha(): count += 1 if count == 3: return True else: count = 0 return False #These "a…

@CheckiO@The Most Numbers

def checkio(*args): nums = list(args) answer = 0 box = 0 length = len(nums) if length < 1: return 0 for i in range(length): for j in range(i, length): if nums[j] > nums[i]: box = nums[i] nums[i] = nums[j] nums[j] = box answer = nums[0] - n…

@CheckiO@Digits Multiplication

def checkio(number: int) -> int: str_num = str(number) list_num = list(str_num) list_num = [int(s) for s in list_num] products = 1 for i in list_num: if i != 0: products = products * i return products if __name__ == '__main__': print('Exam…

@CheckiO@Even the Last

def checkio(array): """ sums even-indexes elements and multiply at the last """ length = len(array) if length == 0: return 0 sums = array[0] for i in range(1, length): if i % 2 == 0: sums = sums + array[i] value = sums * array[-1] return v…

@CheckiO@Right to Left

def left_join(phrases): """ Join strings and replace "right" to "left" """ text = ','.join(phrases) text = text.replace('right', 'left') return text if __name__ == '__main__': print('Example:') print(left_join(("left", "right", "left", "st…