2020. 7. 9. 11:00ㆍ03. Resources/Python
Day_1
https://app.codesignal.com/arcade
Intro.
Q1. add
Write a function that returns the sum of two numbers.
def add(param1, param2):
return param1 + param2
Q2. centuryFromYear
Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.
def centuryFromYear(year):
if year % 100 == 0:
century = int(year / 100)
else:
century = int(year / 100) + 1
return century
Q3. checkPalindrome
Given the string, check if it is a palindrome.
palindrome: 앞으로 읽어도, 뒤로 읽어도 같은 문자열
def checkPalindrome(inputString): return (inputString == inputString[::-1]) # string을 뒤집는 방법 # s = 'abc' # s[::-1] = 'cba'
Q4. adjacentElementsProduct
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
def adjacentElementsProduct(inputArray):
arrFront = inputArray[:-1]
arrRear = inputArray[1:]
arrMul = list()
for i in range(len(arrFront)):
arrMul.append(arrFront[i]*arrRear[i])
return max(arrMul)
Q5. shapeArea
Below we will define an n
-interesting polygon. Your task is to find the area of a polygon for a given n
.
A 1
-interesting polygon is just a square with a side of length 1
. An n
-interesting polygon is obtained by taking the n - 1
-interesting polygon and appending 1
-interesting polygons to its rim, side by side. You can see the 1
-, 2
-, 3
- and 4
-interesting polygons in the picture below.
def shapeArea(n):
area = 0
for i in range(2*n-1,0,-2):
area += i*2
return (area - (2*n-1))
'03. Resources > Python' 카테고리의 다른 글
[Python 문제풀이] 5일차 (0) | 2020.07.13 |
---|---|
[Python 문제풀이] 4일차 (0) | 2020.07.12 |
[Python 문제풀이] 3일차 (0) | 2020.07.11 |
[Python 문제풀이] 2일차 (0) | 2020.07.10 |
파이썬 문제풀이 했던 것 업로드 (0) | 2020.07.09 |