In [ ]:
# run this code to login to https://okpy.org/ and setup the assignment for submission
from ist256 import okclient
ok = okclient.Homework()
Let's use Python's built-in string functions to write our own function to detect if a string is an email address.
The function isEmail(text)
should return True
when text
is an email address, False
otherwise.
For simplicity's sake we will define an email address to be:
@
symbol in it, where the @
is not at the beginning or end of the string and there is a period AFTER the @
symbol. So a@b.c
is considered an email (even though it really isn't). The program should detect emails until you enter quit.
Sample run:
Email address detector. Type quit to exit.
Email: mafudge@syr.edu
mafudge@syr.edu ==> email
Email: mafudge@
mafudge@ ==> NOT EMAIL
Email: mafudge
mafudge ==> NOT EMAIL
Email: @syr.edu
@syr.edu ==> NOT EMAIL
Email: @
@ ==> NOT EMAIL
Email: mafudge@@syr.edu
mafudge@@syr.edu ==> NOT EMAIL
Email: mafudge@syr@edu
mafudge@syr@edu ==> NOT EMAIL
Email: mafudge@syr@edu
mafudge@syr ==> NOT EMAIL
Email: mafudge@syr@edu
mafudge.syr@edu ==> NOT EMAIL
DO NOT GOOGLE "How to detect an email in python"... That's not the point of the exercise. The point is to figure out the problem yourself learning Python's string functions. You will get a ZERO your function uses anything other than string slices and built-in string functions.
Once again we will use the problem simplification technique for writing this program.
First we will write the isEmail(text)
function, then we will write the main program.
In [ ]:
## Step 2: Todo write the function definition for isEmail functiuon
In [ ]:
## Step 3: Write some tests, to ensure the function works, for example
## Make sure to test all cases!
print("WHEN text=mike@syr.edu We EXPECT isEmail(text) to return True", "ACTUAL", isEmail("mike@syr.edu") )
print("WHEN text=mike@ We EXPECT isEmail(text) to return False", "ACTUAL", isEmail("mike@") )
print("WHEN text=mike@syr We EXPECT isEmail(text) to return False", "ACTUAL", isEmail("mike@syr") )
In [2]:
## Step 5: todo write code for full problem, using the isEmail function to help you solve the problem
Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?
To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.
Keep your response to between 100 and 250 words.
--== Write Your Reflection Below Here ==--
In [ ]:
# to save and turn in your work, execute this cell. Your latest submission will be graded.
ok.submit()