Python345 Odd or Even? Task: Given a list of integers, determine whether the sum of its elements is odd or even. Give your answer as a string matching "odd" or "even". If the input array is empty consider it as: [0] (array with a zero). Examples: Input: [0] Output: "even" Input: [0, 1, 4] Output: "odd" Input: [0, -1, -5] Output: "even" Have fun! Solution: 1. Check if the sum of the array is odd. 2. If true, return "od.. 2022. 4. 30. Sort array by string length Description: Write a function that takes an array of strings as an argument and returns a sorted array containing the same strings, ordered from shortest to longest. For example, if this array were passed as an argument: ["Telescopes", "Glasses", "Eyes", "Monocles"] Your function would return the following array: ["Eyes", "Glasses", "Monocles", "Telescopes"] All of the strings in the array passe.. 2022. 4. 29. SQLAlchemy _ NotSupportedError(InvalidCachedStatementError) 에러 해결 AsyncSessionNotSupportedError, InvalidCachedStatementError 테스트 코드를 작성하는 중에 에러가 발생했다!! 에러 메시지는 다음과 같다. """ sqlalchemy.exc.NotSupportedError: (sqlalchemy.dialects.postgresql.asyncpg.InvalidCachedStatementError) : cached statement plan is invalid due to a database schema or configuration change (SQLAlchemy asyncpg dialect will now invalidate all \\ prepared caches in response to this exception) E [.. 2022. 4. 29. Sum of odd numbers Description: Given the triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output) 1 --> 1 2 --> 3 + 5 = 8 Solution: 1. Add up all 'n' numbers. 2. Find the odd number by the added number. 3. It returns after adding 'n' odd numbers from the last. def row_sum_odd_num.. 2022. 4. 28. Python _ 런타임 중에 스크립트 파일 실행하기 스크립트는 보통 직접 명령어를 입력해 실행합니다. 하지만 runtime 환경에서 스크립트 파일을 실행해야할 때도 있습니다. 그런 경우에는 개발자가 직접 터미널에 스크립트 실행 명령어를 치는 것이 아닌, 미리 작성된 파이썬 코드에 의해 스크립트가 실행되도록 해야합니다. 이번 글에는 OS를 사용한 스크립트 실행 방법을 알려드리겠습니다. OS import os os.system("ls") 방법은 아주 간단합니다. os를 import 하고 system 메서드를 사용해 명령어를 안에 넣습니다. 그리고 실행을 해보면 그 결과 값도 함께 보여줍니다. (ls 는 해당 디렉토리를 보여줍니다) >>> project 현재는 project 폴더만 보이네요 하지만 스크립트를 실행하기 위해서 폴더 내로 이동해야 한다고 가정해봅시.. 2022. 4. 28. Mumbling Description: This time no story, no theory. The examples below show you how to write function accum: Examples: accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt" The parameter of accum is a string which includes only letters from a..z and A..Z. Solution: 1. Extract each character from a string with an index. 2. Characters ar.. 2022. 4. 27. 이전 1 ··· 35 36 37 38 39 40 41 ··· 58 다음