68.0k views
3 votes
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.

User VanSkalen
by
8.3k points

1 Answer

2 votes

This Python program reads and processes email IDs of students, creating tuples for email IDs, usernames, and domains. The tuples are printed at the end.

Here's a simple Python program that does what you've described:

```python

def process_email_ids(emails):

usernames = []

domains = []

for email in emails:

# Splitting email into username and domain

username, domain = email.split

# Storing username and domain in respective lists

usernames.append(username)

domains.append(domain)

# Creating tuples

email_tuple = tuple(emails)

username_tuple = tuple(usernames)

domain_tuple = tuple(domains)

return email_tuple, username_tuple, domain_tuple

# Input the number of students

n = int(input("Enter the number of students: "))

# Input email IDs of students

email_list = []

for i in range(n):

email = input(f"Enter email ID for student {i + 1}: ")

email_list.append(email)

# Process email IDs

email_tuple, username_tuple, domain_tuple = process_email_ids(email_list)

# Print the tuples

print("Email IDs Tuple:", email_tuple)

print("Usernames Tuple:", username_tuple)

print("Domains Tuple:", domain_tuple)

```

In this program, we define a function `process_email_ids` that takes a list of email IDs as input, processes them to extract usernames and domains, and then creates three tuples. The main part of the program takes the number of students, reads email IDs, calls the function, and prints the resulting tuples.

User Anderish
by
8.3k points