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

1004. Keep up the hoop

daco2020 2022. 10. 4. 21:01
반응형

Alex just got a new hula hoop, he loves it but feels discouraged because his little brother is better than him

Write a program where Alex can input (n) how many times the hoop goes round and it will return him an encouraging message :)

  • If Alex gets 10 or more hoops, return the string "Great, now move on to tricks".
  • If he doesn't get 10 hoops, return the string "Keep at it until you get it".



Solution:

from functools import lru_cache


def hoop_count(n: int) -> str:
    select = n >= 10 and 1 or 0
    return _get_encouraging_message(select)

@lru_cache(maxsize=2)
def _get_encouraging_message(select: int) -> str:
    return {
        1 : "Great, now move on to tricks", 
        0 : "Keep at it until you get it"
    }[select]


반응형

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

1006. Filter out the geese  (0) 2022.10.06
1005. Palindrome Strings  (0) 2022.10.05
1003. Find the Remainder  (0) 2022.10.03
1002. Twice as old  (0) 2022.10.03
1001. Hello, Name or World!  (0) 2022.10.02