1. Write a function that returns the sum of two numbers.
Example) For param1 = 1 and param2 = 2, the output should be add(param1, param2) = 3.
1
2
3
|
def add(param1, param2):
return param1 + param2
|
2. 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.
Example)
- For year = 1905, the output should be centuryFromYear(year) = 20;
- For year = 1700, the output should be centuryFromYear(year) = 17.
1
2
|
def centuryFromYear(year):
return (year-1) // 100 + 1
|
3. Given the string, check if it is a palindrome.
Example)
- For inputString = "aabaa", the output should be checkPalindrome(inputString) = true;
- For inputString = "abac", the output should be checkPalindrome(inputString) = false;
- For inputString = "a", the output should be checkPalindrome(inputString) = true.
1
2
|
def checkPalindrome(inputString):
return inputString == inputString[::-1]
|
- palindrome : Apalindromeis a string that reads the same left-to-right and right-to-left.
- [start : end : step] 사용 방법 : step 양수 - step만큼 오른쪽으로 이동 / step 음수 - step만큼 왼쪽으로 이동
'Programming > Python' 카테고리의 다른 글
[python] codeSignal 문제풀이 (10) (0) | 2020.01.10 |
---|---|
[python] codeSignal 문제풀이 (9) (0) | 2020.01.10 |
[python] codeSignal 문제풀이 (7~8) (0) | 2020.01.08 |
[python] codeSignal 문제풀이 (4~6) (0) | 2020.01.07 |