Advertisement
Spocoman

10. Weather Forecast - Part 2

Dec 8th, 2021 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. degrees = float(input())
  2.  
  3. if 5 <= degrees < 12:
  4.     print('Cold')
  5. elif 12 <= degrees < 15:
  6.     print('Cool')
  7. elif 15 <= degrees <= 20:
  8.     print('Mild')
  9. elif 20 < degrees < 26:
  10.     print('Warm')
  11. elif 26 <= degrees <= 35:
  12.     print('Hot')
  13. else:
  14.     print('unknown')
  15.  
  16.  
  17. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  18.  
  19. degrees = float(input())
  20.  
  21. weather = ('Cold' if 5 <= degrees < 12 else
  22.            'Cool' if 12 <= degrees < 15 else
  23.            'Mild' if 15 <= degrees <= 20 else
  24.            'Warm' if 20 < degrees < 26 else
  25.            'Hot' if 26 <= degrees <= 35 else 'unknown')
  26.  
  27. print(weather)
  28.  
  29.  
  30. РЕШЕНИЕ С РЕЧНИК:
  31.  
  32. degrees = float(input())
  33.  
  34. weather = {degrees < 5: 'unknown',
  35.            5 <= degrees < 12: 'Cold',
  36.            12 <= degrees < 15: 'Cool',
  37.            15 <= degrees <= 20: 'Mild',
  38.            20 < degrees < 26: 'Warm',
  39.            26 <= degrees <= 35: 'Hot',
  40.            degrees > 35: 'unknown'}
  41.  
  42. print(weather[True])
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement