โ“ Practice Quiz: Control Structures for Renewable Energy Applications

# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment

responses = initialize_assignment("1_practicequiz_q", "week_4", "practicequiz", assignment_points = 25.0, assignment_tag = 'week4-practicequiz')

# Initialize Otter
import otter
grader = otter.Notebook("1_practicequiz_q.ipynb")

โ“ Practice Quiz: Control Structures for Renewable Energy Applications#

Test your understanding of conditional statements (if-else) and loops in Python by solving problems relevant to renewable energy systems, environmental monitoring, and automation tasks.

# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question3
Question3().show()

Renewable Energy Monitoring System#

Renewable energy systems, such as solar panels and wind turbines, generate data that needs to be processed to ensure efficiency and safety. In this task, you will implement a program to monitor energy production and analyze performance.

The program should:

  1. Iterate through a list of energy production measurements (in kilowatt-hours, kWh).

  2. Print a warning message if the energy production drops below a threshold of 50 kWh.

  3. Calculate the average energy production and display it.

  4. Determine if the average energy production meets the optimal threshold (โ‰ฅ 100 kWh) and display a summary message.

Implementation Details#

  1. Define a list of energy production measurements: energy_readings = [120, 95, 85, 45, 150, 90].

  2. Set the optimal energy threshold: optimal_threshold = 100.

  3. Loop through all energy readings and:

    • Print a warning message if the energy production drops below the threshold. The threshold is 50 kWh.

    • Save the energy to the local variable energy.

  4. Calculate the average energy production. Save to the variable average_energy.

    • Print the average energy production value. We have provided the code for you to calculate the average energy. You can use the sum() and len() functions to calculate the average, or the numpy library if you prefer.

  5. Check if the average energy production meets the optimal threshold:

    • If the average energy production is greater than or equal to the optimal threshold, print a message indicating optimal performance.

    • If the average energy production is below the optimal threshold, print a message indicating sub-optimal performance.

    We have provided the print statements for you.

# Define the energy production measurements
...

# Define the optimal energy threshold
...

def energy_production(energy_readings, optimal_threshold):
    # Iterate through energy readings
    ...

        # Check if the energy production is below the threshold
        ...
            print(f"Warning: Energy production dropped below threshold at {energy} kWh!")

    # Calculate the average energy production
    ...

    # Print the average energy production
    print(f"Average energy production: {average_energy:.2f} kWh")

    # Check if the average energy production is optimal
    ...
        print("The average energy production meets the optimal performance threshold.")
    ...
        print("The average energy production is below the optimal performance threshold!")
grader.check("Renewable-Energy-Monitoring")

Submitting Assignment#

Please run the following block of code using shift + enter to submit your assignment, you should see your score.

from pykubegrader.submit.submit_assignment import submit_assignment

submit_assignment("week4-practicequiz", "1_practicequiz_q")