Skip to content

Instantly share code, notes, and snippets.

@bramz
Created January 13, 2019 19:54
Show Gist options
  • Save bramz/284660b2a906d992435b66b86aa9bdea to your computer and use it in GitHub Desktop.
Save bramz/284660b2a906d992435b66b86aa9bdea to your computer and use it in GitHub Desktop.
flower class for data structures and algos book, chapter 2 exercise
"""
Chapter 2
Exercise 2.4
Write a Python class, Flower, that has three instance variables of type str,
int and float, that respectively represent the name of the flower,
its number of petals, and its price. Your class must include a constructor
method that initializes each variable to an appropriate value, and your
class should include methods for setting the value of each type, and
retreiving the value of each type.
"""
class Flower:
def __init__(self):
self.name = str('default')
self.petals = int(0)
self.price = float(0.0)
def set_name(self, name):
self.name = name
def set_petals(self, petals):
self.petals = petals
def set_price(self, price):
self.price = price
def get_name(self) -> str:
return self.name
def get_petals(self) -> int:
return self.petals
def get_price(self) -> float:
return self.price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment