Skip to content
Snippets Groups Projects
Commit db389277 authored by Thomas Röck's avatar Thomas Röck
Browse files

add main.py

parent 323342e9
No related branches found
No related tags found
No related merge requests found
# %% Imports
from bed import Bed
from fruit import Fruit
from plant import FruitBearingPlant
# %% Create objects
plants = [FruitBearingPlant("strawberry", 3, Fruit("strawberry", 55)),
FruitBearingPlant("tomato", 4, Fruit("tomato", 55))]
bed = Bed("in the garden")
# Let's call some methods
c = " >" # cursor
# Method: __str__
print(" Bed Methods ".center(79, "-"))
print(c, "Print informal string representation of <bed>\n")
print(bed, end="\n\n")
# Property: needs_water
print(c, "<bed> needs water?\n")
print(bed.needs_water, end='\n\n')
# Method: water
amount = 9
print(c, f"Water <bed> (amount={amount})\n")
bed.water(amount)
print(bed, end="\n\n")
# Method: plant_plant
print(c, f"Plant plants {plants}\n") # For every plant in the list, the formal string repr. is called (__repr__)
for plant in plants:
bed.plant_plant(plant)
print(f"Planting {plant}") # this calls the informal string representation of the plant
print(f"\n{bed}")
# %%
# bed.water(amount - bed.water_level)
# Method: update
periods = amount // len(plants) # this is the operator for a floor division
print(c, f"Update bed for {periods} periods\n")
for _ in range(periods):
bed.update()
print(f"Plants: {[str(plant) for plant in bed.plants]}\n")
print(bed, end="\n\n")
# Property: water_level.setter
print(c, "Update <bed> and check water_level\n")
bed.update()
print(f"Plants: {[str(plant) for plant in bed.plants]}\n")
# Method: harvest
print(c, "Harvest <bed>\n")
bed_yield = bed.harvest()
print(f"yield: {bed_yield}\n")
print(bed, end="\n\n")
# %%
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment