Question

Supposing we are all celebrities who care about our privacy as much as our programming course...

Supposing we are all celebrities who care about our privacy as much as our programming course grades....we hope our email address and cell phone number are masked if we type them online. Now you need to write a python/java code to realize this masking function.

Requirement: (1) Assuming the input email address is in the format of "[email protected]", all names must be converted to lowercase and all letters between the first and last letter of the name1 must be replaced by 6 asterisks ' * '. length of all names is no smaller than 2.

(2) A cellphone number is a string consisting of only the digits 0-9 or the characters from the set {'+', '-', '(', ')', ' '}. You may assume a phone number contains 10 to 13 digits. The last 10 digits make up the local number, while the digits before those make up the country code. Note that the country code is optional. We want to expose only the last 4 digits and mask all other digits. The local number should be formatted and masked as "***-***-1111", where 1 represents the exposed digits.

To mask a phone number with country code like "+111 111 111 1111"we write it in the form "+***-***-***-1111". The '+' sign and the first '-' sign before the local number should only exist if there is a country code. For example, a 12 digit phone number mask should start with "+**-".

Note that extraneous characters like "(", ")", " ", as well as extra dashes or plus signs not part of the above formatting scheme should be removed. Phone number has length at least 10.

Example 1:

Input: "[email protected]"

Output: "y*****[email protected]" ---->noticing that Y becomes y

Example 2:

Input: "[email protected]"

Output: "c*****[email protected]"

Example 3:

Input: "86-(01)12345678"

Output: "+**-***-***-5678" --> 12 digits, 2 digits for country code and 10 digits for local number

Example 4:

Input: "(312)664-7881"

Output: "***-***-7881" --> 10 digits, which means all digits make up the local number

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def maskMail(mail:str):
    mail=mail.lower()
    at=mail.find('@')
    return mail[0]+5*'*'+mail[at-1]+mail[at:]

def maskMobile(mobile:str):
    digits=0
    for i in mobile:
        if i.isdigit():
            digits+=1
    if digits>10:
        if digits==12:
            return '+**-***-***-'+mobile[-4:]
        else:
            return '+***-***-***-' + mobile[-4:]
    else:
        return '***-***-' + mobile[-4:]

def main():
    mail=input('Enter email address to be masked: ')
    print('Masked mail:',maskMail(mail))
    mobile=input('Enter phone number to be masked: ')
    print('Masked number:',maskMobile(mobile))

if __name__ == '__main__':
    main()

Add a comment
Know the answer?
Add Answer to:
Supposing we are all celebrities who care about our privacy as much as our programming course...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help parsing strings in java, regex can be used. Mask all the digits in a phone...

    Help parsing strings in java, regex can be used. Mask all the digits in a phone number except the last 4 dligits. Each number should be replaced by stan")Input Phone numbers can be with or without country code. Input Phone numbers can only haveorin them along with numbers and spaces. Make sure- is not masked in the output and make sure the number of stars is equal to the number of digits while masking. Phone numbers will always have 10...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

  • As we continue with our study of programming fundamentals, here is a short extra credit programming...

    As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the...

  • JAVA We are learning about java databases in my highschool java class. I Need some help...

    JAVA We are learning about java databases in my highschool java class. I Need some help with it. Create a Java program (feel free to do it all in a main method) that works with a database that contains your 'Contractors' table (see the last exercise). Id (integer, primary key) CompanyName (varchar, 30 characters) Phone(varchar, 12 characters) ContactName(varchar, 30 characters) Rating (integer) OutOfStateService (boolean) # company name phone # Name rating Out of state service 1 Joe's Brewery 1111111111 Joe...

  • In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all...

    In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all the seeds of a integer given by the user. Let’s define a seed of an integer, n, to be a positive value that equals n when multiplied by its individual digits. For example, 23 is a seed of 138 because 23 × 2 × 3 = 138. 111 is an example of a seed of itself because 111 × 1 × 1 × 1...

  • For programming C language This problem will be briefly discussed in Lab2 and the TĀ will...

    For programming C language This problem will be briefly discussed in Lab2 and the TĀ will give you hints to solve it. However, the TĀ will not write the code. This code is a bit complicated, so try to understand the process from the TA so that you can continue working on it at home. Reverse the Number Write a program that takes a 5-digit number as input and print the reverse of the number. Sample Input/Output: Enter a five...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • please use dia to draw the e-r diagram to create Entity - Relationship Diagrams then use MS access This project requires you to create a database design. Your design will be documented in a set o...

    please use dia to draw the e-r diagram to create Entity - Relationship Diagrams then use MS access This project requires you to create a database design. Your design will be documented in a set of Entity-Relationship Crow's Foot diagrams using the representation as shown in the lecture materials. Draw a set of Entity-Relationship diagrams to model the following scenario. The Maggs Realty Company wants to track the Sales Offices that they have across all of Ontario They are interested...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT