Skip to content
Snippets Groups Projects
main.py 2.01 KiB
Newer Older
Thomas Röck's avatar
Thomas Röck committed
# %% Imports
from bed import Bed
from fruit import Fruit
from plant import FruitBearingPlant, RootVegetable
# from root import Root
# %% Create objects
plants = [FruitBearingPlant("strawberry", 3, Fruit("strawberry", 33)),
          FruitBearingPlant("tomato", 4, Fruit("tomato", 16))]

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")
# %%
# Same as above without prints
plants = [FruitBearingPlant("strawberry", 3, Fruit("strawberry", 33)),
          FruitBearingPlant("tomato", 4, Fruit("tomato", 16)),
          RootVegetable("carrot", 1.2, 77, 2)]

bed = Bed("in the garden")

amount = 20
bed.water(amount)

for plant in plants:
    bed.plant_plant(plant)

periods = amount // len(plants)
for _ in range(periods):
    bed.update()
bed.update()
bed_yield = bed.harvest()
# %%
bed_yield
# %%