Advertisement
Spocoman

01. Day of Week

Dec 19th, 2021 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. num = int(input())
  2.  
  3. if num == 1:
  4.     print('Monday')
  5. elif num == 2:
  6.     print('Tuesday')
  7. elif num == 3:
  8.     print('Wednesday')
  9. elif num == 4:
  10.     print('Thursday')
  11. elif num == 5:
  12.     print('Friday')
  13. elif num == 6:
  14.     print('Saturday')
  15. elif num == 7:
  16.     print('Sunday')
  17. else:
  18.     print('Error')
  19.  
  20.  
  21. Фундаменталс решения:)
  22.  
  23. Решение с масив и тернарен оператор:
  24.  
  25. num = int(input())
  26.  
  27. day_of_week = ["Error", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
  28.  
  29. print(day_of_week[num if 0 < num < 8 else 0])
  30.  
  31.  
  32. Решение с речник и тернарен оператор:
  33.  
  34. num = int(input())
  35.  
  36. day_of_week = {
  37.     1: 'Monday',
  38.     2: 'Tuesday',
  39.     3: 'Wednesday',
  40.     4: 'Thursday',
  41.     5: 'Friday',
  42.     6: 'Saturday',
  43.     7: 'Sunday'
  44. }
  45.  
  46. print(f'{day_of_week[num]}' if 0 < num < 8 else 'Error')
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement