Answer to Question #187321 in Python for james

Question #187321

Write the definition of a class WeatherForecast that provides the following behavior (methods):

  • A method called set_skies that has one parameter, a String.
  • A method called set_high that has one parameter, an int.
  • A method called set_low that has one parameter, an int.
  • A method called get_skies that has no parameters and that returns the value that was last used as an argument in set_skies.
  • A method called get_high that has no parameters and that returns the value that was last used as an argument in set_high.
  • A method called get_low that has no parameters and that returns the value that was last used as an argument in set_low.

No constructor need be defined. Be sure to define instance <span style="text-decoration-line: none;">variables</span> as needed by your "get"/"set" methods.


1
Expert's answer
2021-04-29T17:28:55-0400
class WeatherForecast:
    skies= ''
    high = 0
    low = 0    
    def set_skies(self, arg_str):
        self.skies = arg_str
        
    def get_skies(self):
        return(self.skies)
    
    
    def set_high(self, arg_int):
        self.high = arg_int
        
    def get_high(self):
        return(self.high)
    
    def set_low(self, arg_int):
        self.low = arg_int
        
    def get_low(self):
        return(self.low)    
# example test work   
test = WeatherForecast()
test.set_skies('Mainly cloudy')
test.set_high(39)
test.set_low(-5)
print(test.get_skies(),test.get_low(),test.get_high())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS