Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the line_profiler module.
Data Analysis Python
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'cProfile' instead of 'line_profiler'.
Using 'profile' which is a decorator but not the module name.
✗ Incorrect
The line_profiler module is imported to profile code line-by-line.
2fill in blank
mediumComplete the code to create a LineProfiler object.
Data Analysis Python
profiler = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Profile' which is from a different module.
Using 'Timer' which is unrelated.
✗ Incorrect
The LineProfiler class creates a profiler object for line-by-line profiling.
3fill in blank
hardFix the error in the code to add a function to the profiler.
Data Analysis Python
profiler.[1](my_function) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' which executes code but does not add functions.
Using 'add_func' which is not a valid method.
✗ Incorrect
The method add_function adds a function to the profiler to be tracked.
4fill in blank
hardFill both blanks to run the profiler on a function and print the stats.
Data Analysis Python
profiler.[1](my_function) profiler.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' and 'stop' which are not methods of LineProfiler.
Using 'run' twice or 'print_stats' first.
✗ Incorrect
Use run to execute the function under profiling, then print_stats to show results.
5fill in blank
hardFill all three blanks to decorate a function, run it, and print profiling results.
Data Analysis Python
@profiler.[1] def my_function(): total = 0 for i in range(1000): total += i return total my_function() profiler.[2](my_function) profiler.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' as decorator instead of 'profile'.
Not adding the function before printing stats.
✗ Incorrect
Use @profiler.profile to decorate the function, add_function to add it, then print_stats to show results.