IDLE
.
if __name__ == "__main__": p1 = Pet("Henry", "dog", 7) print(p1) p1 = Pet("Henry", "dawg", 7) p1 = Pet("Henry", "dog", "seven") print() p1 = Pet("Henry", "dog", 7) print(p1.get_name()) print(p1.get_type()) print(p1.get_age()) print() p2 = Pet("Felix", "cat", 2) print("Henry age > Felix age:", p1 > p2) p2.older(p1) p1.older(p2) print() p3 = Pet("Angus", "dog", 7) p3.older(p1) p1.older(p3)
Henry, dog, 7 dawg is not a valid pet type seven cannot be converted into an integer Henry dog 7 Henry age > Felix age: True Felix is younger than Henry Henry is older than Felix Henry and Angus are the same age Angus and Henry are the same age
pass
statement. p1 = Pet("Henry", "dog", 7)Add assignment statements for each of the attributes.
if
statement that checks if the
vaule of type is contained in the list
["dog", "cat"]
. try/except
statement. try
block covert the age
value to an integer and set the age
attribute to this value. else
clause print an error message. if
statement that checks if the age of
self is greater than the age of
other. elif
clause that checks if the age of
other is greater than the age of
self. else
clause that prints a message using
the names of the two pets saying that both are the same age. Henry, dog, 7 dawg is not a valid pet type seven cannot be converted into an integer Henry dog 7 Henry age > Felix age: True Felix is younger than Henry Henry is older than Felix Henry and Angus are the same age Angus and Henry are the same age
cd it117/hw/hw10
python3 hw10.py
Henry, dog, 7 dawg is not a valid pet type seven cannot be converted into an integer Henry dog 7 Henry age > Felix age: True Felix is younger than Henry Henry is older than Felix Henry and Angus are the same age Angus and Henry are the same age
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.