crzcas

Weather Inheritance

Feb 21st, 2022
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # Classes, methods and inheritance
  2. class Weather:
  3.  
  4.     def __init__(self, temp, w_speed, w_direction):
  5.         self.temp = temp
  6.         self.w_speed = w_speed
  7.         self.w_direction = w_direction
  8.        
  9.     def current_weather(self):
  10.         print(f"*****Results*****\n")
  11.         print(f"The temperature is {self.temp} deg C.")
  12.         print(f"The wind speed is {self.w_speed} Km/h.")
  13.         print(f"The wind direction is {self.w_direction}.")          
  14.  
  15.        
  16. class VerbalWeather(Weather):
  17.     def wordy_weather(self):
  18.         if temp > 20:
  19.             self.temp = 'warm'
  20.         else:
  21.             self.temp = 'cold'
  22.  
  23.         if w_speed > 30:
  24.             self.w_speed = 'windy'
  25.         else:
  26.             self.w_speed = 'calm'
  27.  
  28.         print(f'Today the temperature is {self.temp}. The Wind speed is {self.w_speed} and the Wind direction is {self.w_direction}.')        
  29.        
  30.  
  31.  
  32. temp = float(input('Type Temperature (deg. C): '))
  33. w_speed = float(input('Type Wind Speed (Km/h): '))
  34. w_direction = (input('Type Direction of the wind (N, S, E, W): '))
  35.      
  36. #current weather    
  37. print()  
  38. weather_object1 = Weather(temp, w_speed, w_direction)  
  39. weather_object1.current_weather()
  40.  
  41.  
  42. #verbal weather with inheritance
  43. print()
  44. weather_object2 = VerbalWeather(temp, w_speed, w_direction)
  45. weather_object2.wordy_weather()
Advertisement
Add Comment
Please, Sign In to add comment