The sample code in Chapter 4 is as follows.
--Point --The length of the list can be calculated with len () and used as the upper limit of the index in the for loop. --Since there is one space between multiple values separated by commas in print, the way to avoid it is to output as one string by concatenating strings.
sample04.py
scores = [60, 50, 60, 58, 54, 54,
58, 50, 52, 54, 48, 69,
34, 55, 51, 52, 44, 51,
69, 64, 66, 55, 52, 61,
46, 31, 57, 52, 44, 18,
41, 53, 55, 61, 51, 44]
length = len(scores)
for i in range(length):
print("Test proposal#" + str(i),"Score:",scores[i])
high_score = max(scores)
max_list = []
for i in range(length):
if scores[i] == high_score:
max_list.append(i)
print("Total number of tests:",length)
print("Highest score:",max(scores))
print("Maximum index:",max_list)
--Output result
Recommended Posts