Advertisement
Spocoman

02. Weekend or Working Day

Dec 19th, 2021 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. day = input()
  2.  
  3. if day == 'Monday' or day == 'Tuesday' or day == 'Wednesday' or day == 'Thursday' or day == 'Friday':
  4.     print('Working day')
  5. elif day == 'Saturday' or day == 'Sunday':
  6.     print('Weekend')
  7. else:
  8.     print('Error')
  9.  
  10. Или така:
  11.  
  12. day = input()
  13.  
  14. if day in ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'):
  15.     print('Working day')
  16. elif day in ('Saturday', 'Sunday'):
  17.     print('Weekend')
  18. else:
  19.     print('Error')
  20.  
  21. Решение с тернарен оператор:
  22.  
  23. day = input()
  24.  
  25. print('Working day' if day in ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday')
  26.       else 'Weekend' if day in ('Saturday', 'Sunday') else 'Error')
  27.  
  28. Решение с масив:
  29.  
  30. day = input()
  31.  
  32. working_day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
  33. weekend = ['Saturday', 'Sunday']
  34.  
  35. print('Working day' if working_day.__contains__(day) else 'Weekend' if weekend.__contains__(day) else 'Error')
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement