Overview: In today’s digital landscape, email communication plays a crucial role in personal and
professional exchanges. Validating email addresses ensures that user inputs are formatted correctly
and can help prevent errors in registration systems. In this exercise, you will create a program that
validates email addresses based on specific criteria.The input for this program will consist of multiple email addresses in a single line, separated by spaces.
The program should first output the validity of each email.A sample input to the program:
mscott@gmail.com jhalpert@domain.ca dschrute@gmail.com $km@gmail.com
pbeesly@spam.ca
Expected output:
Valid
Valid
Valid
Invalid
ForbiddenTo illustrate the parts of an email, consider the address cmput274@ualberta.ca. The part before
the ”@” symbol (cmput274) is the local part of the email. The part to the right of the ”@” symbol
(ualberta.ca) is the domain, which can be further divided into two components: the second-level
domain (ualberta), and the top-level domain (TLD), represented by the extension (.ca).You will write a function called validate email(email) that takes a string input representing an
email address and returns whether the email is ”Valid”, ”Invalid”, or ”Forbidden”.
The following criteria should be used to classify the email addresses:
• Valid: The local part contains only allowed characters (letters, digits, periods, and dashes). The
email must contain exactly one ”@” symbol. The domain part must contain a period ”.” and the
characters after the period (TLD) must be from a list of allowed domain suffixes (.com, .ca,
.org, .net, .gov, .edu).
• Invalid: The email address does not satisfy any of the above properties.
• Forbidden: The email address is valid but belongs to specific forbidden second-level domains
(@scam, @spam, @fakeemail, @trashmail, @pleasenotspam, @therealtaylorswift, @sendmoney).
Examples:Input: john doe@gmail.com
Return: ”Invalid” (Reason: Invalid character ” ”)
Input: jane@domain.co
Return: ”Invalid” (Reason: Invalid domain suffix ”.co”)
Input: jdoe@fakeemail.com
Return: ”Forbidden” (Reason: Forbidden second-level domain)
Input: cmput274@fakeemails.com
Return: ”Valid”Marking Rubric: The code must solve the problem algorithmically. If there is any hardcoding
(e.g., if email == “cmput274@ualberta.ca”: return “Valid”) for the provided test cases, zero
correctness marks will be given.
This question will be marked out of 10 for correctness:
• 30/30: Pass all 10 of the provided test inputs.
• 21/30: Pass any 9 of the provided test inputs.
• 12/30: Pass any 4 (or more) of the provided test inputs.
• 6/30: Pass any of the provided test inputs.Overview: Strings are essential components in modern programming, acting as the primary means
of handling and manipulating textual data. They are widely used in various applications, including
user input processing, data representation, and communication between different software systems.
Strings allow developers to create dynamic content, such as generating web pages or forming database
queries, making them vital for web development and data management. Their flexibility and ease of
use make them indispensable in a wide range of programming tasks, highlighting their importance in
contemporary software development.In this question, your task is to demonstrate your ability to manipulate strings and perform data
analysis on them. Your program will take one sentence as input and perform 3 tasks as follows:
1. Sentence reversal: Reverse the order of words in the input sentence, ensuring that each word
retains its original form while the sequence is inverted.2. Duplicate removal: Remove any duplicate words from the reversed list from task 1, ensuring
that each word appears only once.
3. Median calculation: Analyze the resulting list from task 2 to find the median word length.Tasks 2 and 3 will build on the output of their preceding tasks, which means that the results of task
1 will be used as the input for task 2, and so on.
Input:
Bears, beets, Battlestar Galactica.
Expected output:
Galactica Battlestar beets Bears
Galactica Battlestar beets BearsInput:
Me think, why waste time say lot word, when few word do trick?
Expected output:
trick do word few when word lot say time waste why think Me
trick do word few when lot say time waste why think Me2.1 Sentence Reversal
In this task, you will have to reverse the input sentence. To make the subsequent parts easier, you
should remove all occurrences of a few characters from the input string. Write 2 functions, named
clean input string(string) and reverse string(string). Their responsibilities are explained
below.2.1.1 clean input string(string)
This function will take the input string as a parameter and ”clean it up” so that the subsequent tasks
are easier to execute. In order to clean up the input string, you will have to remove all occurrences of
the following characters from the string:
1. .
2. ,
3. !
5
4. ?
5. ’Example:
Input: The cat and the dog saw the cat jump over the fence while the cat chased the dog
around the yard with the cat and the dog both running.
Output: The cat and the dog saw the cat jump over the fence while the cat chased the dog
around the yard with the cat and the dog both running2.1.2 reverse string(string)
This function will take the “clean” input string (i.e., the output of the clean input string function)
and reverse it.Example:
Input: The cat and the dog saw the cat jump over the fence while the cat chased the dog
around the yard with the cat and the dog both running
Output: running both dog the and cat the with yard the around dog the chased cat the
while fence the over jump cat the saw dog the and cat The
2.2 Duplicate removalIn this part, you will have to write a function named remove duplicates(string) which will take
the reversed string from part 1 as a parameter, and remove all duplicate words from that string. You
should keep the first occurrence of the word and remove all other occurrences. The comparison is case
sensitive, so that means ”The” and ”the” are considered two unique words. But ”the” and ”the” are
duplicate words.Example:
Input: running both dog the and cat the with yard the around dog the chased cat the
while fence the over jump cat the saw dog the and cat The
Output: running both dog the and cat with yard around chased while fence over jump sawThe
2.3 Median calculation
The median is the middle value of a set of numbers when they are arranged in order from smallest to
largest. If the set has an odd number of values, the median is the middle number. If the set has an
even number of values, the median is the average of the two middle numbers.You will have to write a function named calculate median length(string) which will take the string
without any duplicates (from part 2) as a parameter, and calculate the median word length from that
string. The output of this function has to be an integer. Therefore if the actual median is 3.5, then
the output of this function should be 3.Example:
Input: running both dog the and cat with yard around chased while fence over jump saw The
Output: 4
Marking Rubric: This question will be marked out of 30 for correctness (pass test cases):
• 30/30: Pass all 5 of the test cases
• 24/30: Pass 4 of the test cases
6
• 18/30: Pass 3 of the test cases
• 12/30: Pass 2 of the test cases
• 6/30: Pass any of the test cases3 Writing and testing your solution
For the programming questions, you should edit the provided files and add your solution. You can
check your solution by running driver.py. You can see the output of your program in the Output/
folder, and any errors in the Error/ folder.Please do not change the driver file, only edit the solution file.
You can run the driver in a terminal as follows (assuming your working directory is the assignment
folder):
$ cd a s si gnmen t 1
$ cd Que s ti on 1
$ python3 d r i v e r . py
All t e s t s p a s sed !
$ cd . . / Que s ti on 2
$ python3 d r i v e r . py
All t e s t s p a s sed !
$
Please add your name, student number, ccid, operating system and python version at the top of each
solution file by replacing the provided comments.4 Submission Instructions
Please submit a single file to eclass, called ccid.zip. Please create a folder with the name as your
ccid, put your solutions in that folder, zip it and upload it. It is important for the files to have the
same name as described below.
c ci d /
s ol u ti o n Q u e s ti o n 1 . py
s ol u ti o n Q u e s ti o n 2 . py
Assignment, CMPUT, solved
[SOLVED] Cmput 274 assignment 1
$25
File Name: Cmput_274_assignment_1.zip
File Size: 207.24 KB
Reviews
There are no reviews yet.