Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Classes, methods and inheritance
- class Weather:
- def __init__(self, temp, w_speed, w_direction):
- self.temp = temp
- self.w_speed = w_speed
- self.w_direction = w_direction
- def current_weather(self):
- print(f"*****Results*****\n")
- print(f"The temperature is {self.temp} deg C.")
- print(f"The wind speed is {self.w_speed} Km/h.")
- print(f"The wind direction is {self.w_direction}.")
- class VerbalWeather(Weather):
- def wordy_weather(self):
- if temp > 20:
- self.temp = 'warm'
- else:
- self.temp = 'cold'
- if w_speed > 30:
- self.w_speed = 'windy'
- else:
- self.w_speed = 'calm'
- print(f'Today the temperature is {self.temp}. The Wind speed is {self.w_speed} and the Wind direction is {self.w_direction}.')
- temp = float(input('Type Temperature (deg. C): '))
- w_speed = float(input('Type Wind Speed (Km/h): '))
- w_direction = (input('Type Direction of the wind (N, S, E, W): '))
- #current weather
- print()
- weather_object1 = Weather(temp, w_speed, w_direction)
- weather_object1.current_weather()
- #verbal weather with inheritance
- print()
- weather_object2 = VerbalWeather(temp, w_speed, w_direction)
- weather_object2.wordy_weather()
Advertisement
Add Comment
Please, Sign In to add comment