English

Write 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 - Computer Science (Python)

Advertisements
Advertisements

Question

Write 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

Answer in Brief

Solution

Program:
#Program to input names of n students and store them in a tuple.
#Input a name from the user and find if this student is present in the tuple or not.
#Using a user-defined function

#Creating user defined function
def searchStudent(tuple1,search):
    for a in tuple1:
        if(a == search):
            print("The name",search,"is present in the tuple")
            return
    print("The name",search,"is not found in the tuple")

name = tuple()
#Create empty tuple 'name' to store the values
n = int(input("How many names do you want to enter?: "))
for i in range(0,n):
    num = input("> ")
    #It will assign emailid entered by user to tuple 'name'
    name = name + (num,)

print("\nThe names entered in the tuple are:")
print(name)

#Asking the user to enter the name of the student to search
search = input("\nEnter the name of the student you want to search? ")
#Calling the search Student function
searchStudent(name,search)

OUTPUT:
How many names do you want to enter?: 3
> Amit
> Sarthak
> Rajesh

The names entered in the tuple are:
('Amit', 'Sarthak', 'Rajesh')

Enter the name of the student you want to search for. Amit
The name Amit is present in the tuple
shaalaa.com
Tuples
  Is there an error in this question or solution?
Chapter 10: Tuples and Dictionaries - Exercise [Page 224]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 10 Tuples and Dictionaries
Exercise | Q 2. (a) | Page 224

RELATED QUESTIONS

What is the use of the type() function in python?


Write the syntax of creating a Tuple with n number of elements.


What are the advantages of Tuples over a list?


“Lists and Tuples are ordered”. Explain.


When to use a tuple or dictionary in Python. Give some examples of programming situations mentioning their usefulness.


Prove with the help of an example that the variable is rebuilt in case of immutable data types.


TypeError occurs while statement 2 is running. Give reason. How can it be corrected?

>>> tuple1 = (5)         #statement 1
 >>> len(tuple1)         #statement 2

A bank is a financial institution that is involved in borrowing and lending money. With advancements in technology, online banking, also known as internet banking allows customers of a bank to conduct a range of financial transactions through the bank’s website anytime, anywhere. As part of the initial investigation, you are suggested to

  • collect a bank application form. After careful analysis of the form, identify the information required for opening a savings account. Also, enquire about the rate of interest offered for a saving account.
  • The basic two operations performed on an account are Deposit and Withdrawal. Write a menu-driven program that accepts either of the two choices of Deposit and Withdrawal, then accepts an amount, performs the transaction, and accordingly displays the balance. Remember, every bank has a requirement for a minimum balance which needs to be taken care of during withdrawal operations. Enquire about the minimum balance required in your bank.
  • Collect the interest rates for opening a fixed deposit in various slabs in a savings bank account. Remember, rates may be different for senior citizens.

Finally, write a menu-driven program having the following options (use functions and appropriate data types):

  • Open a savings bank account
  • Deposit money
  • Withdraw money
  • Take details, such as the amount and period for a Fixed Deposit, and display its maturity amount for a particular customer.

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.

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×