मराठी

Write a program to read the 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 the second to store domain

Advertisements
Advertisements

प्रश्न

Write a program to read the 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 the 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()]

थोडक्यात उत्तर
Advertisements

उत्तर

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
> [email protected]
> [email protected]
> [email protected]

The email ids in the tuple are:
('[email protected]', '[email protected]', '[email protected]')

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

The domain name in the email ids are:
('gmail.com', 'meritnation.com', 'outlook.com')
shaalaa.com
Concepts of Tuples in Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 10: Tuples and Dictionaries - Exercise [पृष्ठ २२४]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
पाठ 10 Tuples and Dictionaries
Exercise | Q 1. | पृष्ठ २२४
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×