def populate_river(n): '''Randomly populate river of size n with two animals and empty spaces.''' river = [] for _ in range(1, n + 1): occupant = random.choice( [None, animal.Animal('bear'), animal.Animal('fish')]) river.append(occupant) return river
def dodajzwierze(): animal_object = animal.Animal() animal_object.name = input("Jak nazywa się zwierze? ") animal_object.hair = input("Czy zwierze posiada sierść? ") animal_object.feathers = input("Czy zwierze posiada pióra? ") animal_object.eggs = input("Czy zwierze składa jaja? ") animal_object.milk = input("Czy karmi młode mlekiem? ") animal_object.airborne = input("Czy to zwierze latające? ") animal_object.aquatic = input("Czy to zwierze wodne? ") animal_object.predator = input("Czy to drapieżnik? ") animal_object.toothed = input("Czy zwierze posiada uzębienie? ") animal_object.backbone = input("Czy zwierze posiada kręgosłup? ") animal_object.breathes = input("Czy to zwierze oddychające? ") animal_object.venomous = input("Czy to zwierze jadowite? ") animal_object.fins = input("Czy zwierze posiada płetwy? ") animal_object.legs = input("Ile posiada nóg?? ") animal_object.tail = input("Czy zwierze posiada ogon? ") animal_object.domestic = input("Czy to zwierze domowe? ") animal_object.catsize = input("Czy to zwierze wielkości kota? ") print( "Gatunek, który należy wpisać liczbą\n" + '{1: "ssak", 2: "ptak", 3: "gad", 4: "ryba", 5: "płaz", 6: "owad", 7: "inny"}' ) animal_object.type = input("Jakiego gatunku jest zwierzę? ") if input("Enter your option: [T/N]") == "T": model.save_new_data_object(animal_object)
def analiza(): zooData = get_data_from_table('data/zoo.csv') features_names = get_features_names(zooData) X = zooData[features_names] y = zooData['type'] X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) # knn = KNeighborsClassifier() knn = MLPClassifier((16, 10, 7)) knn.fit(X_train, y_train) animal_object = animal.Animal() animal_object.name = input("Jak nazywa się zwierze? ") animal_object.hair = input("Czy zwierze posiada sierść? ") animal_object.feathers = input("Czy zwierze posiada pióra? ") animal_object.eggs = input("Czy zwierze składa jaja? ") animal_object.milk = input("Czy karmi młode mlekiem? ") animal_object.airborne = input("Czy to zwierze latające? ") animal_object.aquatic = input("Czy to zwierze wodne? ") animal_object.predator = input("Czy to drapieżnik? ") animal_object.toothed = input("Czy zwierze posiada uzębienie? ") animal_object.backbone = input("Czy zwierze posiada kręgosłup? ") animal_object.breathes = input("Czy to zwierze oddychające? ") animal_object.venomous = input("Czy to zwierze jadowite? ") animal_object.fins = input("Czy zwierze posiada płetwy? ") animal_object.legs = input("Ile posiada nóg?? ") animal_object.tail = input("Czy zwierze posiada ogon? ") animal_object.domestic = input("Czy to zwierze domowe? ") animal_object.catsize = input("Czy to zwierze wielkości kota? ") # animal_object = animal.Animal().set_test_animal_data() animal_object.type = knn.predict( animal_object.get_animal_data_to_predict())[0] print(animal_object.name + " to " + animal_object.type_name()) if input("Enter your option: [T/N]") == "T": model.save_new_data_object(animal_object) zooData = get_data_from_table('data/zoo.csv')
def kinds_act(player): global pet current = player.location speak(current.description) s = getInputString(pet_types) pet = animal.Animal(player.get_target(s, pet_types, pet_syns)) return get_next(player, current, s)
def make_animal(kind): if kind == 'cat': return cat.Cat() if kind == 'dog': return dog.Dog() if kind == 'sheep': return sheep.Sheep() return animal.Animal(kind)
def male_female(river, available, stays): '''If animals are of the same kind and one is male and other is female, they produce a baby animal of their kind.''' baby_cell = random.choice(available) # Create baby animal and place in random None cell. river[baby_cell] = animal.Animal(river[stays].animal) # Update the list of None cells. available.remove(baby_cell)
def make_animal(kind): """Create an animal class.""" if kind == 'cat': return cat.Cat() if kind == 'dog': return dog.Dog() if kind == 'sheep': return sheep.Sheep() return animal.Animal(kind)
def make_animal(kind): """make animal""" if kind == 'cat': return cat.Cat() if kind == 'dog': return dog.Dog() if kind == 'sheep': return sheep.Sheep() if kind == 'leopard': return leopard.Leopard() return animal.Animal(kind)
def create_animal(kind): """Create an animal class.""" if kind == 'cat': return cat.Cat() if kind == 'dog': return dog.Dog() if kind == 'lion': return lion.Lion() if kind == 'leopard': return leopard.Leopard() if kind == 'sheep': return sheep.Sheep() return animal.Animal(kind)
def add_animal(self, id1, name, type1): try: cursor = self.mydb.cursor() sql = "INSERT INTO Animals (idA, nameA, typeA) VALUES (%s, %s, %s)" val = (id1, name, type1) cursor.execute(sql, val) self.mydb.commit() animal1 = animal.Animal(id1, name, type1) self.list_of_animals.append(animal1) except mysql.connector.IntegrityError: ctypes.windll.user32.MessageBoxW(0, "Duplicate Key!", "Error", 1) except mysql.connector.DatabaseError: ctypes.windll.user32.MessageBoxW(0, "Key needs to be an integer!", "Error", 1)
def main(): earth = world_map.WorldMap(size=(200, 200)) a = animal.Animal(world=earth) t = threading.Thread(target=test, args=( a, earth, )) t.start() while True: time.sleep(0.1) earth.render()
def update_animal_by_id(self, id1, name, type1): id1.replace(" ", "") if id1 != "": for idx in self.list_of_animals: if idx.id1 == id1: self.list_of_animals.pop(idx) animal1 = animal.Animal(id1, name, type1) self.list_of_animals.append(animal1) cursor = self.mydb.cursor() sql = "UPDATE Animals " \ "SET nameA = %s, typeA = %s " \ "WHERE idA = %s" val = (name, type1, id1) cursor.execute(sql, val) self.mydb.commit()
def print_all_animals(self): self.list_of_animals.clear() cursor = self.mydb.cursor() cursor.execute("SELECT * FROM Animals") self.list_of_all_animals = cursor.fetchall() for row in self.list_of_all_animals: animal1 = animal.Animal(row[0], row[1], row[2]) self.list_of_animals.append(animal1) print( "Id = ", row[0], ) print( "Name = ", row[1], ) print("Type = ", row[2]) for idx in self.list_of_animals: print(idx.id1, idx.name, idx.type1)
def __init__(self, *args): self.animal1 = animal.Animal(*args)
import animal, dog, cat anim = animal.Animal('Foo') anim.speak() print() puppy = dog.Dog('Spark', 4) puppy.speak() #print(puppy) print() kitty = cat.Cat('Fluffy', 'persian') kitty.speak()
import animal import human import world world = world.World() animal1 = human.Human(world, "Fred") animal2 = human.Human(world, "Barny") animal3 = human.Human(world, "Allice") animal4 = animal.Animal(world, "Dino") world.moveAnimals() world.identifyAnimals()
import product import mathDojo import car import animal import hospital if __name__ == "__main__": item1 = product.Product(10, "cat toy", 5, "Fisher", 5) print item1 target = store.Store([], "sunnyvale", "mr T") print target md = mathDojo.MathDojo() md.add(2).add(2, 5).subtract(3, 2) print md car1 = car.Car(2000, 35, 'Full', 15) print car animal1 = animal.Animal("Zebra", 100) dragon = animal.Dragon("Eragon") dog = animal.Dog("Corgi") print animal1 print dragon print dog patient1 = hospital.Patient(1, "Dinosaur Rex", "peanuts") hospital = hospital.Hospital("General", 10) print patient1 print hospital
def create_Animal(name, age, height, weight): """Tworzy obiekt klasy Animal""" return animal.Animal(name, age, height, weight)
import farm def make_animal(kind): """Create an animal class.""" if kind == 'cat': return cat.Cat() if kind == 'dog': return dog.Dog() <<<<<<< HEAD if kind == 'lion': return lion.Lion() ======= if kind == 'leopard': return leopard.Leopard() >>>>>>> feature-leopard if kind == 'sheep': return sheep.Sheep() return animal.Animal(kind) def main(animals): animal_farm = farm.Farm() for animal_kind in animals: animal_farm.add_animal(make_animal(animal_kind)) animal_farm.print_contents() if __name__ == '__main__': if len(sys.argv) == 1: print('Pass at least one animal type!') sys.exit(1) main(sys.argv[1:])
import animal import world world = world.World() animal1 = animal.Animal(world, "Fred") animal2 = animal.Animal(world, "Barny") animal3 = animal.Animal(world, "Allice") world.moveAnimals() world.identifyAnimals()
import animal ani = animal.Animal('トクジロウ', 2) ani.show()
# Creamos personas, gracias a la clase importada personaCreada = persona.Persona("Felipe", 20, "Heredia") print(personaCreada.presentacion()) # Exercise 42 Inheritance print("*********# Exercise 42 Inheritance*********") # Creando empleado a partir de persona personaEmpleado = empleado.Empleado("Felipe", 20, "Heredia", "50000") personaEmpleado.presentacion() print(personaEmpleado.implicit()) # Excercise 43 Composition print("*********# Exercise 43 Composition*********") # In the composition, we have an object from another class inside a class # The main class is animal animal1 = animal.Animal("Mono", 20, "Cafe") print("Datos del animal1", animal1.muestraDatos()) animal1.aumentaEdad() print("Datos del animal1", animal1.muestraDatos()) # Then we have an object from familia class # it class have an object of Animal type as a attribute familia1 = familia.Familia("Perro", 4, "Negro") print("Datos del animal de la familia : ", animal1.muestraDatos()) animal1.aumentaEdad() print("Datos del animal de la familia : ", animal1.muestraDatos()) print() # Other Data Structures print("*********# Other Data Structures*********") # Tuple # For declare a tuple we have to follow this structure:
import animal anm = animal.Animal("cat", 100) dog = animal.Dog() drag = animal.Dragon() anm.walk() anm.walk() anm.walk() anm.run() anm.run() anm.display() dog.walk() dog.walk() dog.walk() dog.run() dog.run() dog.pet() dog.display() drag.fly() drag.displayHealth() newAnm = animal.Animal("bash", 50) #>>> newAnm.pet() "AttributeError: 'Animal' object has no attribute 'pet' "" #dog.fly() "AttributeError: 'Dog' object has no attribute 'fly' "
from store import Store import animal from math_dojo import MathDojo import call_center import hospital from underscore import Underscore bmx = Bike(100, "30 mph") print bmx.__repr__() toyota = Car(20000, "120 mph", "Full", 50000) print toyota.__repr__() mouse = Product(10, "Computer Mouse", "5 ounces", "Logitech", 5) print mouse.__repr__() electronics = Store("San Jose, CA", "Me Me") print electronics.__repr__() hamster = animal.Animal("Hammy", 50) print hamster.__repr__() spot = animal.Dog() print spot.__repr__() maggie = animal.Dragon() print maggie.__repr__() al = MathDojo() print al.__repr__() call1 = call_center.Call("Aaron", "268-347-1484", 911, "Complaint") print call1.__repr__() center1 = call_center.CallCenter() print center1.__repr__() patient1 = hospital.Patient(135, "Deborah", "sulfonamides") print patient1.__repr__() general = hospital.Hospital("BB General", 100) print general.__repr__()
import animal class Cat(animal.Animal): def speak(self): print("meow.") def __str__(self): return "cat:" + str(self.name) + ":" + str(self.years) if __name__ == "__main__": myCat = Cat(3) myCat.set_name("Nick") print(myCat) myCat.speak() myAnimal = animal.Animal(99) print(myAnimal) # myAnimal.speak()
import animal, dog #create an instance of animal anim = animal.Animal("DarkAnim") anim.speak() print(anim) #line space print() #create an instance of Dog dg = dog.Dog("Bingo", 5) dg.speak() print(dg) #Exercise #create a class called cat that will inherit from the superclass called Animal #implement the features as done for dog class #create an instance of the cat class to show or test this behaviour as done above