코드로 우주평화

1106. Grasshopper - Messi Goals 본문

나는 이렇게 학습한다/Algorithm & SQL

1106. Grasshopper - Messi Goals

daco2020 2022. 11. 7. 00:58

Messi's Goal Total

Use variables to find the sum of the goals Messi scored in 3 competitions

Information

Messi goal scoring statistics:

Competition Goals

La Liga 43

Champions League 10

Copa del Rey 5

Task

  1. Create these three variables and store the appropriate values using the table above:

  2. la_liga_goals

  3. champions_league_goals
  4. copa_del_rey_goals

  5. Create a fourth variable named total_goals that stores the sum of all of Messi's goals for this year.



Solution:

la_liga_goals = 43
champions_league_goals = 10
copa_del_rey_goals = 5

goals = {
    "la_liga_goals": la_liga_goals,
    "champions_league_goals": champions_league_goals,
    "copa_del_rey_goals": copa_del_rey_goals
}
func = lambda x: sum(x.values())

total_goals = func(goals)