나는 이렇게 학습한다/Algorithm & SQL

0104. Sleigh Authentication

daco2020 2023. 1. 4. 23:28
반응형

Christmas is coming and many people dreamed of having a ride with Santa's sleigh. But, of course, only Santa himself is allowed to use this wonderful transportation. And in order to make sure, that only he can board the sleigh, there's an authentication mechanism.

Your task is to implement the authenticate() method of the sleigh, which takes the name of the person, who wants to board the sleigh and a secret password. If, and only if, the name equals "Santa Claus" and the password is "Ho Ho Ho!" (yes, even Santa has a secret password with uppercase and lowercase letters and special characters :D), the return value must be true. Otherwise it should return false.

Examples:

sleigh = Sleigh()
sleigh.authenticate('Santa Claus', 'Ho Ho Ho!') # must return True

sleigh.authenticate('Santa', 'Ho Ho Ho!') # must return False
sleigh.authenticate('Santa Claus', 'Ho Ho!') # must return False
sleigh.authenticate('jhoffner', 'CodeWars') # Nope, even Jake is not allowed to use the sleigh ;)



Solution:

class Sleigh(object):
    def __init__(self):
        self.__valid_name = "Santa Claus"
        self.__valid_password = "Ho Ho Ho!"

    def authenticate(self, name, password):
        return name == self._get_valid_name() and password == self._get_valid_password()

    def _get_valid_name(self):
        return self.__valid_name

    def _get_valid_password(self):
        return self.__valid_password


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0106. Is there a vowel in there?  (0) 2023.01.07
0105. Greet Me  (0) 2023.01.05
0103. Powers of 2  (0) 2023.01.03
0102. Enumerable Magic #25 - Take the First N Elements  (0) 2023.01.03
0101. Pillars  (0) 2023.01.01