# # Nested data structures. # # Each item in score_1 contains the scores of three homework assignments. scores_1 = [ [96, 89, 97], [88, 84, 83], [64, 57, 72] ] print(f"scores_1: {scores_1}") print(f"scores_1[0]: {scores_1[0]}") print(f"scores_1[2]: {scores_1[2]}") print(f"scores_1[0:1]: {scores_1[0:1]}") print(f"scores_1[:1]: {scores_1[:1]}") print(f"scores_1[::-1]: {scores_1[::-1]}") print(f"scores_1[2][1]: {scores_1[2][1]}") print(f"scores_1[2][::-1]: {scores_1[2][::-1]}") print(f"scores_1[2][1:3]: {scores_1[2][1:3]}") print(f"scores_1[2][:2]: {scores_1[2][:2]}") print(f"scores_1[0:2][1]: {scores_1[0:2][1]}") print(f"scores_1[1:3]: {scores_1[1:3]}") print(f"scores_1[1:3][1]: {scores_1[1:3][1]}") print(""" # Each item in score_1 is the score of three homework assignments. scores_1 = [ [96, 89, 97], [88, 84, 83], [64, 57, 72] ] """) # print the individual scores of each student. for item in scores_1: print(f"student score: ", end="") for score in item: print(score, end=" ") print() print() # putting a comma between scores. for item in scores_1: print(f"student scores: ", end="") for pos, score in enumerate(item): if pos == len(item)-1: print(score) else: print(f"{score}, ", end="") print() # Second version using list comprehensions. for item in scores_1: print(f"student scores: ", end="") str_item = [str(score) for score in item] print(", ".join(str_item)) print() # add student # for student_num, item in enumerate(scores_1): print(f"student #{student_num + 1} scores: ", end="") for pos, score in enumerate(item): if pos == len(item)-1: print(score) else: print(f"{score}, ", end="")