wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Write a program to read email IDs of n number of students and store them in a tuple. Create two new tuples, one to store only the usernames from the email IDs and second to store domain names from the email ids. Print all three tuples at the end of the program. [Hint: You may use the function split()]

Open in App
Solution

Program:
#Program to read email id of n number of students. Store these numbers in a tuple.
#Create two new tuples, one to store only the usernames from
the email IDs and second to store domain names from the email ids.
emails = tuple()
username = tuple()
domainname = tuple()
#Create empty tuple 'emails', 'username' and domain-name
n = int(input("How many email ids you want to enter?: "))
for i in range(0,n):
emid = input("> ")
#It will assign emailid entered by user to tuple 'emails'
emails = emails +(emid,)
#This will split the email id into two parts, username and domain and return a list
spl = emid.split("@")
#assigning returned list first part to username and second part to domain name

username = username + (spl[0],)
domainname = domainname + (spl[1],)

print("\nThe email ids in the tuple are:")
#Printing the list with the email ids
print(emails)

print("\nThe username in the email ids are:")
#Printing the list with the usernames only
print(username)

print("\nThe domain name in the email ids are:")
#Printing the list with the domain names only
print(domainname)


OUTPUT:
How many email ids you want to enter?: 3
> abcde@gmail.com
> test1@meritnation.com
> testing@outlook.com

The email ids in the tuple are:
('abcde@gmail.com', 'test1@meritnation.com', 'testing@outlook.com')

The username in the email ids are:
('abcde', 'test1', 'testing')

The domain name in the email ids are:
('gmail.com', 'meritnation.com', 'outlook.com')

flag
Suggest Corrections
thumbs-up
2
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Sum of Consecutive Numbers
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon