Added lecture 2026113
This commit is contained in:
parent
be356ccb59
commit
5b630435ae
27 changed files with 738 additions and 0 deletions
50
lecture20261103/lists02/dogs-lists09.py
Normal file
50
lecture20261103/lists02/dogs-lists09.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# 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")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue