2025SP_cse160/bigos/lecture20250225/lists02/dogs-lists09.py

51 lines
1.1 KiB
Python

# dogs-lists09
#Dog Description List format = [<dogname>,<age>,<sex>, <breed>]
dogs = [["Mandy", 2, "F", "Chinook"], ["Harry",11,"M", "Chinook"], ["Shenanigans",8,"F", "Chinook"],
["Colorado",10,"F", "Chinook"], ["Katrina", 9, "F", "Chinook"], ["Rusty",10.5,"M", "Golden Retriever" ],
["Tanner", 16, "M", "Golden Retriever"],["Gimli", 2, "M", "Chinook"] ]
# Poor method to print
print(dogs)
# Print the list
positionId = 0
for dog in dogs:
print("{} {}".format(positionId,dog))
positionId += 1
# Print males in the list
print("\n - These are the male dogs")
positionId = 0
for dog in dogs:
if dog[2] == "M":
print("{} {}".format(positionId,dog))
positionId += 1
print("\n")
# Print females in the list
print("\n - These are the female dogs")
positionId = 0
for dog in dogs:
if dog[2] == "F":
print("{} {}".format(positionId,dog))
positionId += 1
print("\n")
# Print ages in the list
print("\n - These are the dogs ages")
positionId = 0
for dog in dogs:
if dog[1] <= 11:
print("{} {}, age = {}".format(positionId,dog,dog[1]))
positionId += 1
print("\n")