본문 바로가기

Python345

Dashatize it Description: Given a variable n, If n is an integer, Return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark. If n is negative, then the negative sign should be removed. If n is not an integer, return an empty value. Ex: dashatize(274) -> '2-7-4' dashatize(6815) -> '68-1-5' Solution: 1. If 'n' is not a number, 'None' is returned. 2.. 2022. 3. 22.
Data Reverse Description: A stream of data is received and needs to be reversed. Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example: 11111111 00000000 00001111 10101010 (byte1) (byte2) (byte3) (byte4) should become: 10101010 00001111 00000000 11111111 (byte4) (byte3) (byte2) (byte1) The total number of bits will always be a multiple of 8. The data is given in a.. 2022. 3. 21.
Persistent Bugger Description: Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit. For example (Input --> Output): 39 --> 3 (because 3*9 = 27, 2*7 = 14, 1*4 = 4 and 4 has only one digit) 999 --> 4 (because 9*9*9 = 729, 7*2*9 = 126, 1*2*6 = 12, and finally 1.. 2022. 3. 20.
내가 쓴 Python 테스트 코드 coverage 알아보기 커버리지란? 테스트 케이스가 얼마나 충족되었는지를 나타내는 지표 중 하나입니다. 테스트를 진행하였을 때 ‘코드 자체가 얼마나 실행되었느냐’는 것이고, 수치를 통해 확인할 수 있습니다. 커버리지를 확인하려면? 테스트 코드를 작성하다보면 내 코드의 커버리지가 얼마나 되는지 궁금해지는데요. 제가 10초만에 커버리지를 확인할 수 있는 방법을 알려드리겠습니다. (테스트 코드가 이미 작성되어있고 테스트를 실행할 수 있는 상황을 가정합니다.) 1. 먼저 coverage 라이브러리를 설치합니다. pip install coverage 2-1. 만약 pytest 를 사용한다면 다음 명령어를 입력해주세요. coverage run -m pytest 2-2. 만약 unittest 를 사용한다면 다음 명령어를 입력해주세요. co.. 2022. 3. 20.
Multiplication table Description: Your task, is to create NxN multiplication table, of size provided in parameter. for example, when given size is 3: 1 2 3 2 4 6 3 6 9 for given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]] Solution: 1. Use the for statement twice to create a two-dimensional array. 2. The numbers in the given array are added in the second for statement. 3. Returns the numbers in a t.. 2022. 3. 19.
Primorial Of a Number Description: Definition (Primorial Of a Number) Is similar to factorial of a number, In primorial, not all the natural numbers get multiplied, only prime numbers are multiplied to calculate the primorial of a number. It's denoted with P# and it is the product of the first n prime numbers. Task Given a number N , calculate its primorial. Notes Only positive numbers will be passed (N > 0) . Input .. 2022. 3. 18.