Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Calculate Weekly Progress | Tracking Athlete Performance
Python for Coaches

bookChallenge: Calculate Weekly Progress

Coaches often need to summarize weekly performance for each athlete. This task will help automate that process. Imagine you are given a list of dictionaries, each representing an athlete with their name and a list of their running distances (in kilometers) for each day of the week. Your goal is to write a function that calculates the total distance run by each athlete during the week and returns a new list of dictionaries with each athlete's name and their total distance.

Завдання

Swipe to start coding

Write a function that takes a list of athlete records, where each record is a dictionary containing the athlete's name under the key "name" and a list of running distances for each day of the week under the key "distances". The function should return a list of dictionaries, each with the athlete's name under "name" and their total distance for the week under "total_distance".

  • Iterate through each athlete in the input list.
  • For each athlete, calculate the sum of their "distances" list.
  • Create a new dictionary with the athlete's "name" and the calculated total distance as "total_distance".
  • Add this dictionary to the result list.
  • Return the result list.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you show me an example of the input data format?

What should the output look like for a sample input?

Do you want the total distance rounded to a specific number of decimal places?

close

bookChallenge: Calculate Weekly Progress

Свайпніть щоб показати меню

Coaches often need to summarize weekly performance for each athlete. This task will help automate that process. Imagine you are given a list of dictionaries, each representing an athlete with their name and a list of their running distances (in kilometers) for each day of the week. Your goal is to write a function that calculates the total distance run by each athlete during the week and returns a new list of dictionaries with each athlete's name and their total distance.

Завдання

Swipe to start coding

Write a function that takes a list of athlete records, where each record is a dictionary containing the athlete's name under the key "name" and a list of running distances for each day of the week under the key "distances". The function should return a list of dictionaries, each with the athlete's name under "name" and their total distance for the week under "total_distance".

  • Iterate through each athlete in the input list.
  • For each athlete, calculate the sum of their "distances" list.
  • Create a new dictionary with the athlete's "name" and the calculated total distance as "total_distance".
  • Add this dictionary to the result list.
  • Return the result list.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

some-alt