본문 바로가기
728x90

프로그래밍 문제53

[CheckIO] Median 1. Problem: py.checkio.org/en/mission/median/ 2. My solution: def checkio(data: List[int]) -> [int, float]: dummy = sorted(data) len_list = len(dummy) # For odd elements if len_list % 2 == 1: return dummy[len_list // 2] # For even elements else: return (dummy[len_list // 2 - 1] + dummy[len_list // 2]) / 2 2021. 3. 23.
[CheckIO] Remove All After 1. Problems : py.checkio.org/en/mission/remove-all-after/ 2. My Solution; def remove_all_after(items: list, border: int) -> Iterable: # your code here return items[:items.index(border) + 1] if border in items else items 2021. 3. 22.
[Check-IO] Lightbulb Intro Problem: py.checkio.org/en/mission/lightbulb-intro/ My solution def sum_light(els: List[datetime]) -> int: """ how long the light bulb has been turned on """ time = 0 for n in range(len(els) // 2): time += (els[2 * n + 1] - els[2*n]).total_seconds() return int(time) 2021. 3. 17.
[CheckIO] Majority Problem: py.checkio.org/en/mission/majority/ My Solution: def is_majority(items: list) -> bool: # your code here return True if items.count(True) > items.count(False) else False if __name__ == '__main__': print("Example:") print(is_majority([True, True, False, True, False])) # These "asserts" are used for self-checking and not for an auto-testing assert is_majority([True, True, False, True, Fals.. 2021. 3. 11.
[CheckIO] Backward Each Word Problem: py.checkio.org/en/mission/backward-each-word/ My solution: def backward_string_by_word(text: str) -> str: # your code here words_list = text.split() # list1 = list(text) # character list that would be substituted by reversed words list2 = list(text) # dummy list that is used to find an index of a word in the list for word in words_list: dummy_str = "".join(list2) # index = dummy_str.fin.. 2021. 3. 10.
[Check-IO] Morse Decoder Problem: py.checkio.org/en/mission/morse-decoder/ My solution: MORSE = {'.-': 'a', '-...': 'b', '-.-.': 'c', '-..': 'd', '.': 'e', '..-.': 'f', '--.': 'g', '....': 'h', '..': 'i', '.---': 'j', '-.-': 'k', '.-..': 'l', '--': 'm', '-.': 'n', '---': 'o', '.--.': 'p', '--.-': 'q', '.-.': 'r', '...': 's', '-': 't', '..-': 'u', '...-': 'v', '.--': 'w', '-..-': 'x', '-.--': 'y', '--..': 'z', '-----': '.. 2021. 3. 8.
[CheckIO] Solve All the same Problems: py.checkio.org/en/mission/all-the-same/ My solution from typing import List, Any def all_the_same(elements: List[Any]) -> bool: # your code here if len(set(elements)) == 1 or len(set(elements)) == 0: return True else: return False if __name__ == '__main__': print("Example:") print(all_the_same([1, 1, 1])) # These "asserts" are used for self-checking and not for an auto-testing assert a.. 2021. 1. 7.
[CheckIO] Solve split list Problem: py.checkio.org/en/mission/split-list/ My solution def split_list(items: list) -> list: # your code here length = len(items) if length % 2 == 0: return [items[:length//2],items[length//2:]] else: return [items[:length//2+1],items[length//2+1:]] if __name__ == '__main__': print("Example:") print(split_list([1, 2, 3, 4, 5, 6])) # These "asserts" are used for self-checking and not for an au.. 2021. 1. 5.
[CheckIO] Sun angle Problem: py.checkio.org/en/mission/sun-angle/ My Solution def sun_angle(time): #replace this for solution hour, min = map(int,time.split(':')) def angle_from_the_sun(hour, min): degree_per_min = float(360 / (60*24)) time = 60 * (hour - 6) + min return round(degree_per_min * time, 2) if (6 2021. 1. 3.
728x90