본문 바로가기
728x90

프로그래밍 문제/[Python] CheckIO50

CheckIO - Even the last Problem: py.checkio.org/en/mission/even-last/ My solution def checkio(array: list) -> int: """ sums even-indexes elements and multiply at the last """ if 0 < len(array) 2020. 12. 8.
CheckIO-sum-numbers Problem: py.checkio.org/en/mission/sum-numbers/ My solution: def sum_numbers(text: str) -> int: # your code here summation = 0 for string in text.split(' '): if string.isdecimal(): summation = summation + int(string) return summation if __name__ == '__main__': print("Example:") print(sum_numbers('hi')) # These "asserts" are used for self-checking and not for an auto-testing assert sum_numbers('h.. 2020. 12. 7.
CheckIO - correct-sentence Problems: py.checkio.org/en/mission/correct-sentence/ My Solutions def correct_sentence(text: str) -> str: """ returns a corrected sentence which starts with a capital letter and ends with a dot. """ # your code here if not (text[-1] == '.'): text = text + '.' text = text[0].upper() + text[1:] return text if __name__ == '__main__': print("Example:") print(correct_sentence("greetings, friends")) .. 2020. 12. 6.
CheckIO - between-markers-simplified Problems: py.checkio.org/en/mission/between-markers-simplified/ My Solution def between_markers(text: str, begin: str, end: str) -> str: """ returns substring between two given markers """ # your code here return text[text.index(begin)+1:text.index(end)] if __name__ == '__main__': print('Example:') print(between_markers('What is >apple', 'apple', '', 'apple', ' 2020. 12. 5.
CheckIO - Nearest value Problem: py.checkio.org/en/mission/nearest-value/ My solution def nearest_value(values: set, one: int) -> int: # your code here n = 0 while(not (one + n in values or one - n in values)): n = n + 1 if one - n in values: return one - n else: return one + n if __name__ == '__main__': print("Example:") print(nearest_value({4, 7, 10, 11, 12, 17}, 9)) # These "asserts" are used for self-checking and n.. 2020. 12. 2.
728x90