| Store | Cart

[Tutor] Not sure what I'm doing wrong with these 2 python scripts

From: Anton Gilb <anto...@gmail.com>
Tue, 19 Nov 2013 18:22:32 -0600
Not sure what I'm doing wrong, here are the problems and what I have for
answers so far.


1.)Write the definition of a class  Counter containing:
An instance variable  named  counter of type  int .
A constructor that takes one  int argument and assigns its value to  counter
A method named  increment that adds one to  counter . It does not take
parameters or return a value.
A method named  decrement that subtracts one from  counter . It also does
not take parameters or return a value.
A method named  get_value that returns the value of the instance variable
counter .

class Counter(object):
    def __init__(self, ct):
        self.counter = ct
    def increment(self):
        self.counter += 1
    def decrement(self):
        self.counter -= 1
    def get_value(self):
        return self.counter

2.)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):
        self.skies = ""
    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):
        self.low = value

_______________________________________________
Tutor maillist  -  Tut...@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Recent Messages in this Thread
Anton Gilb Nov 20, 2013 12:22 am
Andreas Perstinger Nov 20, 2013 09:51 am
Steven DAprano Nov 20, 2013 10:30 am
Messages in this thread