Advertisements
Advertisements
Question
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
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
> [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')APPEARS IN
RELATED QUESTIONS
Write the syntax of creating a Tuple with n number of elements.
What are the advantages of Tuples over a list?
What is a nested tuple? Explain with an example.
“Lists and Tuples are ordered”. Explain.
What advantages do tuples have over lists?
When to use a tuple or dictionary in Python. Give some examples of programming situations mentioning their usefulness.
TypeError occurs while statement 2 is running. Give reason. How can it be corrected?
>>> tuple1 = (5) #statement 1
>>> len(tuple1) #statement 2Write a program to input the names of n students and store them in a tuple. Also, input a name from the user and find if this student is present in the tuple or not. We can accomplish these by:
writing a user-defined function
Participating in a quiz can be fun as it provides a competitive element. Some educational institutes use it as a tool to measure the knowledge level, abilities, and/or skills of their pupils either on a general level or in a specific field of study. Identify and analyze popular quiz shows and write a Python program to create a quiz that should also contain the following functionalities besides the one identified by you as a result of your analysis.
- Create an administrative user ID and password to categorically add, modify, or delete a question.
- Register the student before allowing her or him to play a quiz.
- Allow selection of category based on the subject area.
- Display questions as per the chosen category.
- Keep the score as the participant plays.
- Display the final score.
Our heritage monuments are our assets. They are a reflection of our rich and glorious past and an inspiration for our future. UNESCO has identified some Indian heritage sites as World heritage sites. Collect the following information about these sites:
- What is the name of the site?
- Where is it located?
District
State - When was it built?
- Who built it?
- Why was it built?
- The website link (if any).
Write a Python program to
- create an administrative user ID and password to add, modify or delete an entered heritage site in the list of sites.
- display the list of world heritage sites in India.
- search and display information about a world heritage site entered by the user.
- display the name(s) of world heritage site(s) on the basis of the state input by the user.
