[Python] CodeSignal 문제 풀이 (1~3)

2020. 2. 5. 22:17Python/CodeSignal Algorithm

1. Write a function that returns the sum of two numbers.

For param1 = 1 and param2 = 2, the output should be add(param1, param2) = 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.

  • For year = 1905, the output should becenturyFromYear(year) = 20;
  • For year = 1700, the output should becenturyFromYear(year) = 17;
def centuryFromYear(year):
    if((year % 100) == 0):
        return year / 100
    else:
        return (int)((year / 100) + 1)

 

3. Given the string, check if it is a palindrome.

  • 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.
def checkPalindrome(inputString):
    return inputString == inputString[::-1]