Challenge - 5 Problems
Sensor Alert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output when sensor value exceeds threshold?
Consider this Python code snippet running on a Raspberry Pi that reads a temperature sensor and sends an email alert if the temperature exceeds 30°C. What will be printed if the sensor reads 32°C?
Raspberry Pi
temperature = 32 threshold = 30 if temperature > threshold: print("Alert: Temperature too high!") else: print("Temperature is normal.")
Attempts:
2 left
💡 Hint
Check the condition comparing temperature and threshold.
✗ Incorrect
Since 32 is greater than 30, the condition is true, so the alert message is printed.
🧠 Conceptual
intermediate1:00remaining
Which component is essential for sending email alerts from Raspberry Pi?
To send email alerts when a sensor threshold is crossed on a Raspberry Pi, which of the following is essential?
Attempts:
2 left
💡 Hint
Think about how emails are sent programmatically.
✗ Incorrect
An SMTP server is needed to send emails from the Raspberry Pi using code.
🔧 Debug
advanced2:30remaining
Why does this email alert code fail to send?
This Python code snippet is intended to send an email alert when the sensor value is above threshold. Why does it fail to send the email?
Raspberry Pi
import smtplib sensor_value = 45 threshold = 40 if sensor_value > threshold: server = smtplib.SMTP('smtp.example.com', 587) server.ehlo() server.starttls() server.login('user@example.com', 'password') message = 'Subject: Alert\n\nSensor value exceeded threshold.' server.sendmail('user@example.com', 'alert@example.com', message) server.quit()
Attempts:
2 left
💡 Hint
Check the SMTP protocol sequence for secure connection.
✗ Incorrect
The SMTP protocol requires an EHLO command before starting TLS to identify the client to the server.
📝 Syntax
advanced1:30remaining
Identify the syntax error in this sensor alert code
What is the syntax error in the following Python code that reads a sensor and sends an alert?
Raspberry Pi
temperature = 28 threshold = 25 if temperature > threshold: print('Alert: High temperature!')
Attempts:
2 left
💡 Hint
Check the if statement syntax carefully.
✗ Incorrect
Python requires a colon ':' at the end of the if condition line.
🚀 Application
expert2:00remaining
How many email alerts are sent by this code?
This Python code reads sensor values from a list and sends an email alert for each value above 50. How many emails will be sent?
Raspberry Pi
sensor_values = [45, 52, 60, 48, 55] threshold = 50 alerts_sent = 0 for value in sensor_values: if value > threshold: # send email alert (code omitted) alerts_sent += 1 print(alerts_sent)
Attempts:
2 left
💡 Hint
Count how many values in the list are greater than 50.
✗ Incorrect
Values 52, 60, and 55 are above 50, so 3 alerts are sent.