Get startedGet started for free

Report-generating function

You learned that functions can return values, but they can also print results.

Your development team needs regular reports on test execution times. Instead of manually calculating these metrics each time, you'll create a custom function called test_report that prints a formatted summary without returning any values.

A test_durations list with test execution times in seconds is provided for you.

This exercise is part of the course

Intermediate Python for Developers

View Course

Exercise instructions

  • Complete the function definition by adding durations as the argument.
  • Calculate the total test time by using a built-in function on the durations.
  • Generate the report for recent tests by calling the function on the test_durations list.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

test_durations = [245.50, 189.99, 312.75, 156.20, 428.90, 201.35, 167.80]

 # Complete the function
def test_report(____):
    num_tests = len(durations)
    
    # Calculate total test time
    total_time = ____(____)
    
    print("=== Test Report ===")
    print("Total Tests: ", num_tests)
    print("Total Execution Time (s): ", total_time)

# Generate the report for recent test runs
____(____)
Edit and Run Code