[Tutor] Not sure what I'm doing wrong with these 2 python scripts
Anton Gilb
antongilb at gmail.com
Wed Nov 20 01:22:32 CET 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131119/b74b088a/attachment-0001.html>
More information about the Tutor
mailing list