Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
NBA Stats Application
The Helper Function
5. Getting a player index
Core Functions
Menu Functions
Putting it all together

Instruction

Good job! One of the menu options will check the relationship between a player and a club. To that end, we'll need a function that asks the user to pick a player index from the list of players. Let's write it now.

Exercise

Create a function named get_player_index(players) that accepts a list of players and:

  1. Lists all the players' indexes with their names, each in the following format:
    >> {index} {firstname} {lastname}
    Here's an example:
    >> 0 Marcin Gortat
    >> 1 Kevin Durant
    
  2. Asks the user to pick a player's index. Use the following prompt:
    >>> Pick player index: 
    
  3. Returns the user's choice as an integer.

Assume that the user always provides a correct index value.

Stuck? Here's a hint!

Because you want to print all players' indexes, use the following for loop:

for i in range(len(players)):

To get the index from the user, use the input() function. Remember to convert the result to an integer.