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 by - 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:

using the built-in function

Answer in Brief
Advertisements

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 built-in function

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)

search=input("\nEnter the name of the student you want to search? ")

#Using membership function to check if name is present or not
if search in name:
    print("The name",search,"is present in the tuple")
else:
    print("The name",search,"is not found in the tuple")

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. Animesh
The name Animesh is not present in the tuple
shaalaa.com
Tuple Methods and Built-in Functions
  Is there an error in this question or solution?
Chapter 10: Tuples and Dictionaries - Exercise [Page 225]

APPEARS IN

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

RELATED QUESTIONS

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(tuple1.index(45))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(tuple1.count(45))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(len(tuple2))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(max(tuple1))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(min(tuple1))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

print(sum(tuple2))

Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)

Find the output of the following statement:

p r i n t ( s o r t e d ( t u p l e 1 ) )
print(tuple1)

Every mode of transport utilizes a reservation system to ensure its smooth and efficient functioning. If you analyze you would find many things in common. You are required to identify any one mode of transportation and prepare a reservation system for it. For example, let us look at the Railway reservation system we talked about earlier. The complex task of designing a good railway reservation system is seen as designing the different components of the system and then making them work with each other efficiently. Possible subsystems are shown in Figure 1. Each of them may be modelled using functions.

Write a python code to automate the reservation needs of the identified mode of transport.

Railway reservation system


Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×