Wednesday, 21 January 2015

creating a farm

This is the main program (field_class) which is the basis of all the farm and which you open to access and manage your farm. It calls upon all the other programs such as cow_class and wheat_class which are kept in the same folder to fill the farm:

from potato_class import * from wheat_class import * from sheep_class import * from cow_class import * class Field: """simulation of the farm""" def __init__(self,max_animals,max_crops): self._crops = [] self._animals = [] self._max_animals = max_animals self._max_crops = max_crops def plant_crop(self, crop): if len(self._cropss) < self._max_crops: self._crops.append(crop) return True else: return False def add_animal(self, animal): if len(self._animals) < self._max_animals: self._animals.append(animal) return True else: return False def harvest_crop(self,position): return self._crops.pop(position) def remove_animal def main(): new_field = Field(5,2) print(new_field._crops) print(new_field._animals) print(new_field._max_animals) print(new_field._max_crops) new_field.plant_crop(Wheat()) new_field.add_animal(Sheep("le sheep")) print(new_field._crops) print(new_field._animals) if __name__ == '__main__': main()
This is an example of one off the classes that the main program calls upon for information about either a crop or an animal which can populate the farm. Since all of these are similar in terms of code used i will only use one as an example:
from crop_class import * class Potato(Crop): """A POTATO CROP""" #constructor def __init__(self): #call the parent class constructor with default values for potato #growth rate = 1; light need = 3; water need = 6 super().__init__(1,3,6) self._type = "potato" #override grow method of subclass def grow(self,light,water): if light >= self._light_need and water >= self._water_need: if self._status == "Seedling" and water > self._water_need: self._growth += self._growth_rate * 1.5 elif self._status == "Young" and water > self._water_need: self._growth += self._growth_rate * 1.25 else: self._growth += self._growth_rate #increatment day growing self._days_growing += 1 #Update the status self._update_status() def main(): #create a new potato crop potato_crop = Potato() print(potato_crop.report()) #manually grow the crop manual_grow(potato_crop) print(potato_crop.report()) if __name__ == "__main__": main()

Wednesday, 10 December 2014

questions using def

an interesting alternative to the traditional if and else...

Monday, 1 December 2014

advanced use of def

in this code i pass parameters and check if usernames are already taken.

Saturday, 29 November 2014

loops with def

this program lets the user continually add people to the list of names due to loops, this can be used to make multiple emails to different people as in mail merge... 

Wednesday, 26 November 2014

using DEF in mailmerge

This program helps you create lists that you could use in mailmerge.

Monday, 24 November 2014

def

differant versions of def function 

Saturday, 18 October 2014