问题:用相同的Dog类,实例化三只新狗,每只狗的年龄不同。然后编写一个名为get_biggest_number()的函数,它接受任意数量的年龄并返回最旧的函数。然后输出最老的狗的年龄.
class Dog:
# Class Attributes
species = 'mammal'
# Initializer /Instance Attributes
def __init__(self, name, age):
self.name = name
self.age = age
# Print the name of the oldest dog
def get_biggest_number(list):
name = ""
age = 0
for i in range(len(list)): # len(list[a, b, c]) calc the leth of the list
if list[i].age > age:
age = list[i].age
name = list[i].name
print("oldest dog is " + name)
dog_a = Dog("aaa", 5)
dog_b = Dog("bbb", 6)
dog_c = Dog("ccc", 7)
dog_list = [dog_a, dog_b, dog_c]
# Use the function
get_biggest_number(dog_list)