Question

In: Computer Science

In python, how do I define a function (check_domain) which takes a email (string) and domain...

In python, how do I define a function (check_domain) which takes a email (string) and domain name (string) as input. using slice, it will return true if the email address' domain same matches the input domain name. For example, when input are ”[email protected]” and ”msn.com”, the function you defined should return True. When input are ”[email protected]” and ”hotmail.com”, it should return False

Solutions

Expert Solution

Steps:

· email and domain name were got as input

· check_domain() is called the return value is checked using if

· if the return value is true then email domain matches with the domain name given

· otherwise does not matches.

· check_domain() function takes email and the domain name as parameters

· using the split function it splits the email by @ symbol

· dom has the list of literals seperated by the @ symbol

· dom[0] will have mail id and dom[1] will have the domain name

· therefore dom[1] is compared with domain name passed and if it is equal it sends true

· otherwise false.

Code:

#check_domain() function takes email and the domain name as parameters

# using the split function it splits the email by @ symbol

# dom has the list of literals seperated by the @ symbol

#dom[0] will have mail id and dom[1] will have the domain name

# therefore dom[1] is compared with domain name passed and if it is equal it sends true

# otherwise false

def check_domain(email,domain):

    dom=email.split("@")

    if domain==dom[1]:

        return True

    else:

        return False

# email and domain name were got as input

# check_domain() is called the return value is checked using if

# if the return value is true then email domain matches with the domain name given

# otherwise does not matches.

email=input("Enter Email : ")

domain=input("Enter Domain Name : ")

if check_domain(email,domain):

    print(email + " matches the " + domain)

else:

    print(email + " does not matches the " + domain)

Screenshot:

Output:

Enter Email : [email protected]

Enter Domain Name : msn.com

[email protected] matches the msn.com

Enter Email : [email protected]

Enter Domain Name : hotmail.com

[email protected] does not matches the hotmail.com

Do follow the indentation of the code as in the screenshot. In Python indentation matters a lot.


Related Solutions

python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Python question Define a function called hash_string_weighted_folding(string_to_hash, modulus) that takes two parameters: a string variable string_to_hash...
Python question Define a function called hash_string_weighted_folding(string_to_hash, modulus) that takes two parameters: a string variable string_to_hash and an integer called modulus. The function returns an integer that is the hash value of string_to_hash. This hash function processes the string in blocks of 4 characters (the final block may be shorter depending on the length of string_to_hash) and multiplies each character’s ASCII value by a weight. The weight depends on the position of the character in the block of 4 characters:...
Write functions that do the following in Python: i) A function that takes 2 arguments and...
Write functions that do the following in Python: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Python: How would I modify the class below that takes a string and returns an object...
Python: How would I modify the class below that takes a string and returns an object holding a valid NANP phone number. I am asked to filll in the three methods listed, but underfined, below: __str__(), area_code(), and normalize(). My task is to clean up differently formatted telephone numbers by removing punctuation, such as '(', '-', and the like, and removing and the country code (1) if present. I am asked to start by stripping non-digits, and then see if...
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
Define a function file_to_hist() which takes a string representing a filename, opens the file, reads its...
Define a function file_to_hist() which takes a string representing a filename, opens the file, reads its contents, closes the file,* and returns a histogram based on the letter frequencies in the given file. If no such file exists, your function should return an empty histogram (i.e., an empty dictionary {}). So for example, if the file nash.txt was in the same directory as char_hist3.py and had the following contents: I have never seen a purple cow, And I never hope...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Python: How would I write a function that takes a directory and a size in bytes,...
Python: How would I write a function that takes a directory and a size in bytes, and returns a list of files in the directory or below that are larger than the size. For example, I can use this function to look for files larger than 1 Meg below my Home directory.
Python: How would I write a function that takes a URL of a webpage and finds...
Python: How would I write a function that takes a URL of a webpage and finds the first link on the page? The hint given is the function should return a tuple holding two strings: the URL and the link text.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT