0
0
Raspberry Piprogramming~20 mins

Email alerts on sensor thresholds in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sensor Alert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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.")
AAlert: Temperature too high!
BTemperature is normal.
CNo output
DError: sensor not found
Attempts:
2 left
💡 Hint
Check the condition comparing temperature and threshold.
🧠 Conceptual
intermediate
1: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?
ASMTP server configuration
BGPIO pin setup only
CBluetooth pairing
DLCD display connection
Attempts:
2 left
💡 Hint
Think about how emails are sent programmatically.
🔧 Debug
advanced
2: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()
AIncorrect SMTP port number
BMissing server.ehlo() call before starttls()
CNo subject line in the message
DUsing starttls() without login
Attempts:
2 left
💡 Hint
Check the SMTP protocol sequence for secure connection.
📝 Syntax
advanced
1: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!')
AVariable names not defined
BIncorrect indentation of print statement
CUsing single quotes instead of double quotes
DMissing colon ':' after if condition
Attempts:
2 left
💡 Hint
Check the if statement syntax carefully.
🚀 Application
expert
2: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)
A2
B4
C3
D5
Attempts:
2 left
💡 Hint
Count how many values in the list are greater than 50.