示例#1
0
def main():
    dog_1 = Dog('Druzhok', 5, 'Alex', 20, 0.5)
    cat_1 = Cat('Zhook', 18, 'john', 10, 0.2)
    parrot_1 = Parrot('Alexei', 80, 'Oleg', 10, 0.1, 'Ara')
    print(Pet.get_counter())
    print(dog_1.get_counter())
    mule_1 = Mule('Ia', 20, 'Iakov', 40, 0.7)
    mule_1.voice()
示例#2
0
def main():

    log = Logger()
    log.info('Hello')

    a = Dog('Claus', 'female')
    print(a.get_gender())

    a.age = 12
    print(a.age)

    b = Dog('Claus', 'female')
    print(a)
    print(b)

    p = Puddle('Jens', 'Female')

    print(p)
def main():
    dog_1 = Dog('Druzhok', 10, 'John', 15, 0.4)
    cat_1 = Cat('Zhook', 7, 'Alex', 8, 0.2)
    parrot_1 = Parrot('Alexey', 59, 'Oleg', 0.4, 0.2, 'ara')
    dog_1.change_weight(3)
    dog_1.change_height(.1)
    call_voice(dog_1, cat_1)
示例#4
0
from classes import Cat, Dog

cat = Cat()
cat.set_size("small") # Big, meduim or small
cat.get_size()
cat.feed("milk") # Cat's eat only milk
cat.need_to_feed()
dog = Dog()
dog.set_size("Big")
dog.get_size()
dog.feed("milk") # Cat's eat only meat
dog.need_to_feed()

示例#5
0
for i in range(len(newownerlist)):
    print(newownerlist[i].toString())
print("--------------------")

# list of objects with references

owner1 = Owner(1, "Jack")
owner2 = Owner(2, "Jill")

ownerlist = []

ownerlist.append(owner1)
ownerlist.append(owner2)

dog1 = Dog("Fido", owner1)
dog2 = Dog("Pluto", owner2)
dog3 = Dog(dogowner=owner1)

doglist = []

doglist.append(dog1)
doglist.append(dog2)
doglist.append(dog3)

objectlist = []

objectlist.append(ownerlist)
objectlist.append(doglist)

dogownerfile = open("listdogowner", "wb")
示例#6
0
#
# Dont forget to import the new class!
#
# In the code below initiate a new variable called `dog` with the *Dog
# class*. Give dog the name "Gordon" and eye color "brown".
#
# Put cat and dog variables in a list. Iterate through the list and
# concatenate the result from their description methods together in a string,
# without any seperation between the two string.
#
# Answer with the string.
#
# Write your code below and put the answer into the variable ANSWER.
#

dog = Dog("brown", "Gordon")

animals = [cat, dog]
answer = ""

for i in animals:
    answer += i.description()

ANSWER = answer

# I will now test your answer - change false to true to get a hint.
dbwebb.assert_equal("1.6", ANSWER, True)

# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Exercise 1.7 (1 points)
#
示例#7
0
#!/usr/bin/python3
#encoding: utf-8
from classes import Dog
from time import sleep

dog1 = Dog('bilu', 2, 'pitbull')
dog2 = Dog('rex', 1, 'poodle')
dog1.andar()
dog1.dormir()
while True:
    print(dog1.nome)
    if dog1.energia > 0 and dog1.fome > 0:
        dog1.andar()
    if dog1.energia == 0:
        dog1.dormir()
        sleep(1)
    if dog1.fome == 0:
        dog1.comer()
        sleep(1)
    sleep(2)
import classes
from classes import Dog

print '*' * 20
dog1 = Dog('sydney', 'yip', 'crate', 35)
dog1.print_habitat()


def my_print(*splat_args):
    for i in splat_args:
        print i,


my_print(1, '2', 3)
示例#9
0
		self.breed = 'mixed'

	def sit(self):
		print(f"{self.name} is now sitting.")

	def roll_over(self):
		print(f"{self.name} rolled over!")

	def get_long_name(self):
		return f"{self.name} the Dog"

	def set_name(self, name):
		self.name=name

#Creating an instance and accessing attributes
dog = Dog('Jack', 6)
print(f"{dog.name} is {dog.age} years old.")

#Modifying attributes
dog.age=12
print(f"{dog.name} is {dog.age} years old.")

#Calling methods
dog.sit()
dog.roll_over()

#Using a getter and setter
dog.set_name('Clover')
print(dog.get_long_name())

#How to import classes
示例#10
0
#The program is just used as practice problems in chapter 9 of 
#Python Crash Course, Eric Matthes
#classes
#by Jason Delancey
from classes import Dog, HotDog

my_dog = Dog('willie', 6)
print("My dog's name is " + my_dog.name.title() + ".")
print("My dog is " + str(my_dog.age) + " years old.")
my_dog.sit()
my_dog.roll_over()
print()
your_dog = Dog('Jamie', 4)
print("Your dog's name is " + your_dog.name.title() + ".")
print("Your dog is " + str(your_dog.age) + " years old.")
your_dog.sit()
your_dog.roll_over()
print()

my_hotdog = HotDog("Simon", 5)
my_hotdog.sit()
my_hotdog.roll_over()
示例#11
0
from classes import Dog, Bulldog, RussellTerrier

snoopy = Dog("Snoopy", 12)
bob = Dog("Bob", 5)
tody = Dog("Tody", 7)

ted = Bulldog("Ted", 3)

#Mostra que as instancias sao diferentes
print(snoopy == bob)
#Mostra o tipo do objeto d1
print(type(snoopy))

#Acessando os atributos das instancias.
print("{} is {} years old and {} is {} years old.".format(
    snoopy.name, snoopy.age, bob.name, bob.age))

if snoopy.specie == "mammal":
    print("{0} is {1}".format(snoopy.name, snoopy.specie))

print(snoopy.description())
print(snoopy.speak("Gruff gruff"))
print(ted.description())
print(ted.run("fast"))

#verifica se uma classe e uma instancia de outra.
print(isinstance(ted, Dog))
print(isinstance(snoopy, Bulldog))
print(isinstance(ted, RussellTerrier))