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

1219. Return the day

daco2020 2022. 12. 19. 22:11
반응형

Complete the function which returns the weekday according to the input number:

  • 1 returns "Sunday"
  • 2 returns "Monday"
  • 3 returns "Tuesday"
  • 4 returns "Wednesday"
  • 5 returns "Thursday"
  • 6 returns "Friday"
  • 7 returns "Saturday"
  • Otherwise returns "Wrong, please enter a number between 1 and 7"



Solution:

days = {
    1: "Sunday",
    2: "Monday",
    3: "Tuesday",
    4: "Wednesday",
    5: "Thursday",
    6: "Friday",
    7: "Saturday"
}

def whatday(num: int) -> str:
    try:
        return days[num]
    except KeyError:
        return "Wrong, please enter a number between 1 and 7"


반응형

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

1221. Name Shuffler  (0) 2022.12.21
1220. The 'if' function  (0) 2022.12.20
1218. Remove First and Last Character  (0) 2022.12.18
1217. Regexp Basics - is it a digit?  (0) 2022.12.17
1216. Define a card suit  (0) 2022.12.17