-4

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.

class WeatherForecast(object):
    def __init__ (self, skies, value):
        self.skies = ""
        value = 0
    def get_skies():
        return self.set_skies
    def set_skies(self, value)
        self.skies = value
    def get_high():
        return self.set_high
    def set_high(self, value):
        self.high = value
    def get_low():
        return self.set_low
    def set_low(self, value):
        self.low = value

class WeatherForecast():

skies = "Clear"
high = 80
low = 20 

def set_skies(self, skies)
    self.skies = skies

def get_skies(self):
    return self.skies

def set_high(self, high):
    self.high = high

def get_high(self):
    return self.high

def set_low(self, value):
    self.low = value

def get_low(self):
    return self.low
Waleed Qutob
  • 57
  • 1
  • 3
  • 7
  • There doesn't appear to be an actual question in this though? – MasterOdin May 14 '15 at 02:14
  • that was my answer. It's incorrect, so i need help solving it. – Waleed Qutob May 14 '15 at 02:15
  • it is not really python code. check http://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work – Dyno Fu May 14 '15 at 02:16
  • oh sorry missed the indention... i'll fix that – Waleed Qutob May 14 '15 at 02:17
  • 1
    Congratulations on being given an assignment by someone who thinks Python is just another form of Java. He's wrong for assigning it, and you're wrong for asking us to do your homework for you. – msw May 14 '15 at 02:21
  • I really don't want someone to do my homework for me... I've been trying for more than an hour to solve only this question but no luck, so that's why i need help to know what's causing it to say it's wrong – Waleed Qutob May 14 '15 at 02:35

4 Answers4

1
class WeatherForecast():
      skies = ""
      high = 0
      low = 0
      def set_skies(self, skies):
          self.skies = skies
      def get_skies(self):
          return self.skies
      def set_high(self, high):
          self.high = high
      def get_high(self):
          return self.high
      def set_low(self, low):
          self.low = low
      def get_low(self):
          return self.low
Waleed Qutob
  • 57
  • 1
  • 3
  • 7
  • It was the Codelab problem... if i kept the skies = "Cloudy" or whatever when the function set_skies get's called it can be changed... but it only worked when i made skies and empty string :/ and high = 0 and low = 0 anyways it worked :) – Waleed Qutob May 14 '15 at 05:41
0

It seems as though you are missing some instance variables for you class.

The spec requires you have one String for describing the skies (ie cloudy, sunny) and two integers that represent the low and high temperatures for the day (ie low of 23 and high of 45)

the spec says you do not have to deal with them in a constructor, yet you may if you wish.

Since this is a homework assignment I assume, I will put you on the right course; however I don't want to give you the answer.

Variables:

  1. string for the skies
  2. int for the low temp
  3. int for the high temp

Functions:

  1. get/set for skies. get should return self.skies, set should set the instance variable for the skies.

  2. get/set for low temp. get should return self.low, set should set the instance variable for the low temp.

  3. get/set for high temp. get should return self.high, set should set the instance variable for the high temp.

Good luck with your assignment.

If you feel like looking up some syntax here is the link for python classes. https://docs.python.org/2/tutorial/classes.html

Edit: I did not give the op this code, they wrote it (minus one missing colon)

class WeatherForecast():
    skies = "Clear"
    high = 80
    low = 20 
    def set_skies(self, skies):
        self.skies = skies
    def get_skies(self):
        return self.skies
    def set_high(self, high):
        self.high = high
    def get_high(self):
        return self.high
    def set_low(self, value):
        self.low = value
    def get_low(self):
        return self.low

You would run this code by making an object of the class type and running these class methods on it.

ie)

w = WeatherForecast()
w.set_skies("clear")
w.set_low(20)
w.set_high(30)

w.get_skies()
w.get_low()
w.get_high()
Andrew Malta
  • 850
  • 5
  • 15
  • Thanks a lot :) i'll try and see if that works :) Because i've tried a lot of things that's why the variables are missing, i added them before, but it didn't work. I'll try again. – Waleed Qutob May 14 '15 at 02:23
  • Ok, if my answer helps make sure to let me know. If you are still having trouble, just ask and I will clarify. – Andrew Malta May 14 '15 at 02:25
  • it didn't work :/ tried everything, i've added the new answer to the main thread – Waleed Qutob May 14 '15 at 02:31
  • it works , you just forgot a colon :) check out the end of the set_skies function, you need a colon. Otherwise it looks good to me – Andrew Malta May 14 '15 at 02:38
  • Didn't work :/ any other suggestion ? because the values in the truth table didn't match with it, when they give it input it gives the same values that i gave it in the variables :/ – Waleed Qutob May 14 '15 at 02:48
  • I just ran the code, on my end. I'll edit my answer to what code I used of yours that worked on my machine. – Andrew Malta May 14 '15 at 02:54
  • *ahem ...* "in the end, it *does* seem to me that "we just gave Waleed the answer to his *homework!*" Which basically means that he probably will have learned nothing. I don't think that this exchange has done Waleed any lasting service. *(Two years from now, he'll be flushing-out on technical interviews, and probably blaming the university.)* "Just sayin'" ... – Mike Robinson May 14 '15 at 03:20
  • I would usually agree; however Waleed did end up writing all of the code (minus forgetting a colon) and I think he/she ended up understanding why it worked. – Andrew Malta May 14 '15 at 03:27
  • @MikeRobinson It didn't work, i'm sure i had the correct answer the first time and i know what i'm doing, but it doesn't seem to work, whatever answer i gave it, it still didn't work, so that's why i need help – Waleed Qutob May 14 '15 at 03:29
  • You certainly did not have the correct answer the first time; however the code that you wrote the second time is completely functional and conforms to the specs. I would email the teacher for more clarification if you are still not passing the tests. – Andrew Malta May 14 '15 at 03:31
  • @AndrewMalta i meant the very first time that i haven't posted here, and i made 46 tries to solve it, but it still didn't work :/ you sure there is nothing wrong with it ? – Waleed Qutob May 14 '15 at 03:32
  • Are you getting syntax errors when you run the code? Do you have specific test cases that you can share with us? – Andrew Malta May 14 '15 at 03:34
  • Waleed ... *(how can I say this "gracefully, and publicly")* ... *aren't you(?!)* actually asking The Internet to "do your **homework** for you?" The first computer-program that I ever wrote: *"was eight lines long, took me six months to write, and had a bug in it."* (That was in the year 1977.) I've written a million-and-a-half lines since then, and *(if I may say ...)* made a bunch-o-money doing it. What good do you now imagine that it will it do you, to "short-cut the learning process?" Do you HONESTLY think that this business **is** as easy as it looks?! *(Ahem... just sayin'...)* – Mike Robinson May 14 '15 at 03:38
  • @MikeRobinson I'm an ethical hacker, not a programmer. I can code in Pascal, C, C++, Java, Vb, Vb.net, VBS, Web Languages(HTML, PHP, JQuery, JS). For me this question was because i'm pretty sure i know what i'm doing, but for some reason it isn't working. So i decided to ask people here to help me answer it, and you're right it is technically asking someone to solve it, but i've tried, and i can't try for 6 months because the due date is tomorrow morning. So i hope you understand what i mean :) – Waleed Qutob May 14 '15 at 03:52
  • "Due-date is tomorrow morning?" *Homework!* (How can I say it? I've been the one who *assigned* such homework, for more than 9 years.) Uhhh... let's just say for-the-record that you can't "try for 6 months" to deal with something that is "due tomorrow," unless somehow it was *actually* assigned 6-months plus-one-day ago ... which I doubt. Your OP is, *quite transparently,* "a Homework Assignment," and I am sorry to say that: "you will not have learned a <!> thing." Good day to you, sir. – Mike Robinson May 14 '15 at 04:15
  • @MikeRobinson I already figured it out, but thanks for helping out :) – Waleed Qutob May 14 '15 at 05:51
0

Enter it just like this for myProgrammingLab. (Include the 'class WeatherForecast:" part.

class WeatherForecast:

    def __init__(self):
    self.skies=""
    self.low=0
    self.high=0

def set_skies(self,skies):
    self.skies = skies

def set_high(self, high):
    self.high = high

def set_low(self, low):
    self.low = low

def get_skies(self):
    return self.skies

def get_high(self):
    return self.high

def get_low(self):
    return self.low
Dhia
  • 10,119
  • 11
  • 58
  • 69
0
class WeatherForecast:

   def  __init__(self):
       self.skies=""
       self.low=0
       self.high=0

    def set_skies(self,skies):
         self.skies = skies

    def set_high(self,high):
         self.high = high

     def set_low(self,low):
         self.low = low

     def get_skies(self):
         return self.skies

     def get_high(self):
         return self.high
     def get_low(self):
         return self.low

dan=WeatherForecast()

You have to call WeatherForecast to get it to work on Myprogramming lab