Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the module needed to send emails.
Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like random or time.
✗ Incorrect
The smtplib module is used to send emails in Python.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or equal operators instead of greater than.
✗ Incorrect
We want to send an alert when the sensor value is greater than the threshold.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting quotes around the server address.
✗ Incorrect
The SMTP server address must be a string, so it needs quotes.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using server address or recipient email instead of login credentials.
✗ Incorrect
You must provide your email and password as strings to log in.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using password instead of sender email in sendmail.
✗ Incorrect
The subject and body are strings, and the sender email is needed to send the mail.