Python类和方法

bw6*_*293 2 python methods class

我有python编程的在线练习题.我坚持这个问题:

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 variables  as needed by your "get"/"set" methods. 
Run Code Online (Sandbox Code Playgroud)

我有这个答案,但我不知道问题是什么.它一直在告诉我某处的价值不正确.

class WeatherForecast (object):
    def __init__ (self):
        self.skies = ''
        self.high = ''
        self.low  = ''
    def set_skies (self, value):
        self.skies = value
    def set_high (self, value):
        self.high = value
    def set_low (self):
        self.low = low
    def get_skies (self):
        return self.skies
    def get_high(self):
        return self.high
    def get_low(self):
        return self.low
Run Code Online (Sandbox Code Playgroud)

Ale*_*ton 5

你没有定义skies,highlow.

也许在你set事物的功能中,你的意思是:

def set_high (self, value):  # Do this for all setting functions.
    self.high = value  # value is defined, so will work.
Run Code Online (Sandbox Code Playgroud)