0
0
Raspberry Piprogramming~10 mins

Email alerts on sensor thresholds in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the module needed to send emails.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Arandom
Btime
Csmtplib
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like random or time.
2fill in blank
medium

Complete the code to check if the sensor value exceeds the threshold.

Raspberry Pi
if sensor_value [1] threshold:
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or equal operators instead of greater than.
3fill in blank
hard

Fix the error in the code to create an SMTP connection.

Raspberry Pi
server = smtplib.SMTP([1], 587)
Drag options to blanks, or click blank then click option'
A'smtp.gmail.com'
Bsmtp.gmail.com
C'localhost'
Dlocalhost
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting quotes around the server address.
4fill in blank
hard

Fill both blanks to log in to the SMTP server with email and password.

Raspberry Pi
server.login([1], [2])
Drag options to blanks, or click blank then click option'
A'your_email@example.com'
B'your_password'
C'smtp.gmail.com'
D'recipient@example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using server address or recipient email instead of login credentials.
5fill in blank
hard

Fill all three blanks to send an email alert with subject and body.

Raspberry Pi
message = f"Subject: [1]\n\n[2]"
server.sendmail([3], 'recipient@example.com', message)
Drag options to blanks, or click blank then click option'
A"Sensor Alert!"
B"The sensor value exceeded the threshold."
C'your_email@example.com'
D'your_password'
Attempts:
3 left
💡 Hint
Common Mistakes
Using password instead of sender email in sendmail.