Create a function named do_action(players, user_choice)
. It should invoke a function based on user_choice
, which will be a string.
Inside the function, you should first invoke the return_sorted_clubs(players)
function and assign the result to a clubs
variable. Then, for user_choice
equal:
'1'
– invoke show_sorted_players(players)
.
'2'
– invoke show_top_player_in_club(players, clubs)
.
'3'
– invoke show_player_club_relation(players, clubs)
.
'4'
– invoke show_player_most_clubs(players)
.
For all other input, print 'Incorrect choice!'
In the previous exercises, we assumed that user always provides correct output. Now that we use those functions in a do_action()
function, we should provide that user doesn't get an error when choosing incorrect option somewhere in the application – incorrect number (e.g., 58
) or a string which can't be converted to an integer (e.g., 'answer 1'
). When a user types an incorrect answer, our function should always print 'Incorrect choice!'
.