Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- class Fish:
- type = 'Fish'
- def __init__(self):
- self.weight = random.randint(1, 9)
- class PredatoryFish(Fish):
- type = 'PredatoryFish'
- def __init__(self):
- super().__init__()
- self.weight = 10
- class Aquarium:
- type = 'Aquarium'
- def __init__(self):
- self.peaceful_fishes = {}
- self.predatory_fishes = {}
- def add_peaceful_fishes(self, fish_count):
- self.peaceful_fishes = {'fish'+str(fish):Fish().weight for fish in range(fish_count)}
- def add_predators(self):
- names = ('predator1', 'predator2')
- self.predatory_fishes = {name:PredatoryFish().weight for name in names}
- def simulate_hunting(self):
- for fish in list(self.peaceful_fishes):
- kg = self.peaceful_fishes.pop(fish)
- rand = random.choice(list(self.predatory_fishes))
- self.predatory_fishes[rand] += kg
- # uncomment line bellow to see logs hunting
- # print('{0}(weight = {1}kg) was eaten by {2}(weight = {3})'.format(fish, kg, rand, self.predatory_fishes.get(rand)))
- def get_winner(self):
- pass # TODO
- if __name__ == '__main__':
- aquarium = Aquarium()
- aquarium.add_peaceful_fishes(random.randint(10, 50))
- print(aquarium.peaceful_fishes)
- aquarium.add_predators()
- print(aquarium.predatory_fishes)
- aquarium.simulate_hunting()
- print(aquarium.peaceful_fishes)
- print(aquarium.predatory_fishes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement