Created
April 10, 2021 04:08
-
-
Save sontek/447ad12231fa7e486d761d061caeb5c6 to your computer and use it in GitHub Desktop.
Graham's (9 years old) first Python program - Classifying animals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Required Attributes: | |
1. Vertabrate or Invertebrate | |
2. Fur or No Fur | |
3. Feathers or No Feathers | |
4. Gills or No gills | |
5. Scales or No Scales | |
""" | |
class Attributes: | |
# True = Vertabrate | |
# False = Invertabrate | |
has_backone = False | |
has_fur = False | |
has_feathers = False | |
has_gills = False | |
has_scales = False | |
has_legs_on_head = False | |
# Mammal | |
class Dog(Attributes): | |
def __init__(self): | |
self.name = 'Dog' | |
self.has_backone = True | |
self.has_fur = True | |
# Bird | |
class Chicken(Attributes): | |
def __init__(self): | |
self.name ="Chicken" | |
self.has_backone = True | |
self.has_feathers = True | |
# Reptile | |
class Iguana(Attributes): | |
def __init__(self): | |
self. name = "Iguana" | |
self.has_backone = True | |
self.has_scales = True | |
# Fish | |
class Shark(Attributes): | |
def __init__(self): | |
self.name ="Shark" | |
self.has_backone = True | |
self.has_gills = True | |
class Octopus(Attributes): | |
def __init__(self): | |
self.name = "Octopus" | |
self.has_gills = True | |
self.has_legs_on_head = True | |
# Arthropod | |
class Crab(Attributes): | |
def __init__(self): | |
self.name="Crab" | |
self.has_gills = True | |
class Spider(Attributes): | |
def __init__(self): | |
self.name="Spider" | |
class Shrimp(Attributes): | |
def __init__(self): | |
self.name = 'Shrimp' | |
self.has_gills = True | |
class Frog(Attributes): | |
def __init__(self): | |
self.name = 'Frog' | |
self.has_backone = True | |
self.has_gills = 'sometimes' | |
animals = [ | |
Dog(), | |
Chicken(), | |
Iguana(), | |
Shark(), | |
Octopus(), | |
Crab(), | |
Spider(), | |
Shrimp(), | |
Frog(), | |
] | |
for animal in animals: | |
if animal.has_backone: | |
# vertabrate | |
if animal.has_fur: | |
print(f'{animal.name} is mammal') | |
elif animal.has_feathers: | |
print(f'{animal.name} is bird') | |
elif animal.has_gills: | |
if animal.has_gills == 'sometimes': | |
print(f'{animal.name} is amphibian') | |
else: | |
print(f'{animal.name} is fish') | |
else: | |
print(f'{animal.name} is reptile') | |
else: | |
# invertabrate | |
if animal.has_legs_on_head: | |
print(f'{animal.name} is cephalopod') | |
else: | |
print(f'{animal.name} is arthropod') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment