0
0
Simulinkdata~15 mins

Generated C code inspection in Simulink - Mini Project: Build & Apply

Choose your learning style9 modes available
Generated C code inspection
📖 Scenario: You work as a data analyst in a company that uses Simulink to generate C code for embedded systems. Your task is to inspect the generated C code metrics to understand code complexity and size.
🎯 Goal: Build a Python program that stores generated C code metrics, filters metrics based on a threshold, and displays the filtered results.
📋 What You'll Learn
Create a dictionary with exact metric names and values
Add a threshold variable to filter metrics
Use a dictionary comprehension to filter metrics above the threshold
Print the filtered dictionary
💡 Why This Matters
🌍 Real World
Inspecting generated C code metrics helps engineers understand code complexity and maintainability in embedded systems.
💼 Career
Data analysts and software engineers often analyze code metrics to improve software quality and performance.
Progress0 / 4 steps
1
Create the metrics dictionary
Create a dictionary called code_metrics with these exact entries: 'Lines of Code': 1200, 'Cyclomatic Complexity': 15, 'Function Count': 45, 'Comment Percentage': 20
Simulink
Hint

Use curly braces {} to create a dictionary with key-value pairs separated by commas.

2
Add a threshold variable
Create a variable called threshold and set it to 30 to filter metrics with values greater than this number.
Simulink
Hint

Just assign the number 30 to the variable threshold.

3
Filter metrics above threshold
Use a dictionary comprehension to create a new dictionary called filtered_metrics that contains only the entries from code_metrics where the value is greater than threshold. Use for metric, value in code_metrics.items() in your comprehension.
Simulink
Hint

Use the syntax: {key: value for key, value in dictionary.items() if condition}

4
Display the filtered metrics
Print the filtered_metrics dictionary to display the metrics with values above the threshold.
Simulink
Hint

Use print(filtered_metrics) to show the filtered dictionary.