Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

The last make task of the chapter, and the one that needs a loop inside a loop.

A local sports club stores the full names of its team members in a list. They need a program that turns every name into its initials.

The data

So that the output can be checked automatically, the names are fixed. Start your program with exactly this line:

players = ["Alex Smith", "Jordan Taylor", "Sam Brown"]

Your task

Write a program that:

The first initial is always the first character of the name. The last initial is the character straight after the space, and the space can be anywhere, because first names have different lengths. That is what the inner loop is for: it finds out where the space is in this particular name.

The tests also check your code: a program that does not have a for loop inside a for loop, or that does not call upper(), does not pass.

The output

One line per player, in the order they are in the list, each holding two capital letters and nothing else:

AS
JT
SB
Help! My code doesn't work!

Make sure that you check for the following things:

  • The outer loop runs over range(len(players)) and picks out one full name each time round.
  • The inner loop runs over the characters of that one name, not over the list.
  • The two loops have different counter names.
  • The last initial is at the position after the space: one more than the index where the space was found.
  • The print belongs to the outer loop, not the inner one, so it runs once per player. Printing inside the inner loop prints far too many lines.
  • The two initials are joined with + and no space in between.