Spot PII Before You Post
Intermediate · Write the code · from Safe Computing: Privacy, Passwords, Encryption and Phishing
From the lesson: How do attackers get in?
- Malware is software meant to damage a computer system or take partial control of it. Ransomware locks your files until you pay; spyware secretly watches what you do. - A computer virus is a malicious program that can copy itself and get into a computer without permission.
Read this part of the lessonWrite has_pii(text) that returns True if a message contains an email address or a phone number, and False otherwise. Check each word (split on spaces) after stripping the characters .,!? from its ends:
@, at least one character before it, and a . somewhere after it.555-867-5309.has_pii("Call me at 555-867-5309 tonight") -> True
has_pii("Meet at 5pm in room 204") -> Falsedef has_pii(text):
for word in text.split():
word = word.strip(".,!?")
# Return True if word is an email address or a phone number
return False
What Check runs
Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| print(has_pii("Call me at 555-867-5309 tonight")) | True |
| print(has_pii("My email is sam.lee@example.com.")) | True |
| print(has_pii("Meet at 5pm in room 204")) | False |
More Safe Computing exercises
- Caesar Cipher for Any TextIntermediate
- Count the Possible PasswordsIntermediate