Advertisement
Spocoman

Cat Life

Jan 7th, 2022 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. breed = input()
  2. gender = input()
  3. years = 0
  4.  
  5. if breed == 'Siberian':
  6.     years = 11
  7. elif breed == 'American Shorthair':
  8.     years = 12
  9. elif breed == 'British Shorthair':
  10.     years = 13
  11. elif breed == 'Persian':
  12.     years = 14
  13. elif breed == 'Siamese':
  14.     years = 15
  15. elif breed == 'Ragdoll':
  16.     years = 16
  17. else:
  18.     print(f'{breed} is invalid cat!')
  19.  
  20. if gender == 'f':
  21.     years += 1
  22.  
  23. if years > 1:
  24.     print(f'{years * 2} cat months')
  25.  
  26. ФУНДАМЕНТАЛС РЕШЕНИЯ:
  27.  
  28. Решение с тернарен оператор:
  29.  
  30. breed = input()
  31. gender = input()
  32.  
  33. years = 11 if breed == 'Siberian' else \
  34.         12 if breed == 'American Shorthair' else \
  35.         13 if breed == 'British Shorthair' else \
  36.         14 if breed == 'Persian' else \
  37.         15 if breed == 'Siamese' else \
  38.         16 if breed == 'Ragdoll' else 0
  39.  
  40. print(f'{(years + (1 if gender == "f" else 0)) * 2} cat months' if years > 1 else f'{breed} is invalid cat!')
  41.  
  42.  
  43. Решение с колекция:
  44.  
  45. breed = input()
  46. gender = input()
  47.  
  48. years = {'Siberian': 11, 'American Shorthair': 12, 'British Shorthair': 13, 'Persian': 14, 'Siamese': 15, 'Ragdoll': 16}
  49.  
  50. print(f'{(years[breed] + (1 if gender == "f" else 0)) * 2} cat months' if breed in years else f'{breed} is invalid cat!')
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement