Skip to main content
Chapter 10 of 11
NCERT Solutions

Tuples and Dictionaries

CBSE · Class 11 · Computer Science

NCERT Solutions for Tuples and Dictionaries — CBSE Class 11 Computer Science.

42 questions68 flashcards5 concepts

Interactive on Super Tutor

Studying Tuples and Dictionaries? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.

1,000+ Class 11 students started this chapter today

17 Questions Solved · 1 Section

9 worked solutions below. Unlock all 17 free in Super Tutor

EXERCISE

1Consider the following tuples, tuple1 and tuple2:

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

Find the output of the following statements:
i. print(tuple1.index(45))
ii. print(tuple1.count(45))
iii. print(tuple1 + tuple2)
iv. print(len(tuple2))
v. print(max(tuple1))
vi print(min(tuple1))
vii. print(sum(tuple2))
viii. print(sorted(tuple1))
print(tuple1)
Show solution
Using tuple operations:

- `tuple1.index(45)` gives the index of the first `45`, which is `2`.
- `tuple1.count(45)` counts all `45`s, which is `3`.
- `tuple1 + tuple2` concatenates the tuples.
- `len(tuple2) = 2`
- `max(tuple1) = 67`
- `min(tuple1) = 1`
- `sum(tuple2) = 100 + 200 = 300`
- `sorted(tuple1)` returns a list in ascending order.
- `print(tuple1)` prints the original tuple unchanged.

So the outputs are:

i. `2`
ii. `3`
iii. `(23, 1, 45, 67, 45, 9, 55, 45, 100, 200)`
iv. `2`
v. `67`
vi. `1`
vii. `300`
viii. `[1, 9, 23, 45, 45, 45, 55, 67]`

`(23, 1, 45, 67, 45, 9, 55, 45)`

Not sure why a step works? check your working in Super Tutor

2Consider the following dictionary stateCapital:
stateCapital = {"AndhraPradesh":"Hyderabad",
"Bihar":"Patna","Maharashtra":"Mumbai",
"Rajasthan":"Jaipur"}
Find the output of the following statements:
i. print(stateCapital.get("Bihar"))
ii. print(stateCapital.keys())
iii. print(stateCapital.values())
iv. print(stateCapital.items())
v. print(len(stateCapital))
vi print("Maharashtra" in stateCapital)
vii. print(stateCapital.get("Assam"))
viii. del stateCapital["Rajasthan"]
print(stateCapital)
Show solution
From the dictionary operations in the chapter:

- `stateCapital.get("Bihar")` returns the value for `Bihar`, which is Patna.
- `keys()`, `values()`, and `items()` return the dictionary views in the same order the items were entered.
- `len(stateCapital)` is `4`.
- `"Maharashtra" in stateCapital` checks for the key, so it is `True`.
- `stateCapital.get("Assam")` returns `None` because the key is not present.
- After deleting `"Rajasthan"`, the remaining dictionary is shown.

So the outputs are:

i. `Patna`
ii. `dict_keys(['AndhraPradesh', 'Bihar', 'Maharashtra', 'Rajasthan'])`
iii. `dict_values(['Hyderabad', 'Patna', 'Mumbai', 'Jaipur'])`
iv. `dict_items([('AndhraPradesh', 'Hyderabad'), ('Bihar', 'Patna'), ('Maharashtra', 'Mumbai'), ('Rajasthan', 'Jaipur')])`
v. `4`
vi. `True`
vii. `None`
viii. `{'AndhraPradesh': 'Hyderabad', 'Bihar': 'Patna', 'Maharashtra': 'Mumbai'}`

Not sure why a step works? check your working in Super Tutor

3"Lists and Tuples are ordered". Explain.Show solution
A list and a tuple are both ordered sequences. This means that every element has a fixed position, so the order in which elements are stored is maintained.

Because they are ordered, we can access elements by index. For example, the first element is at index 00, the second at index 11, and so on. In a list or tuple, the same set of elements arranged in a different order is considered different.

So, saying "Lists and Tuples are ordered" means their elements are stored in a definite sequence and can be accessed by position.

Not sure why a step works? check your working in Super Tutor

4With the help of an example show how can you
return more than one value from a function.
Show solution
A function can return more than one value by returning a tuple.

Example:

```python
def circle(r):
area = 3.14 * r * r
circumference = 2 * 3.14 * r
return (area, circumference)

radius = 5
area, circumference = circle(radius)
print(area)
print(circumference)
```

Here, the function `circle()` returns two values: area and circumference. These are packed into a tuple and then unpacked into two variables on the left side of the assignment.

Not sure why a step works? check your working in Super Tutor

5What advantages do tuples have over lists?Show solution
Tuples have these advantages over lists:

- Tuples are immutable: once created, their elements cannot be changed accidentally.
- Because they do not change, iterating through a tuple is faster than through a list.
- Tuples are useful for storing data that should remain fixed, such as records.

So, tuples are better when the data is not meant to change.

Not sure why a step works? check your working in Super Tutor

6When to use tuple or dictionary in Python. Give some
examples of programming situations mentioning
their usefulness.
Show solution
Use a tuple when the data is fixed and should not be changed. For example:

- storing a student's roll number, name, and marks together
- storing a record that must remain unchanged

Use a dictionary when data needs to be stored as key-value pairs and accessed by a key. For example:

- storing names of students as keys and their marks as values
- storing state names as keys and capital cities as values
- storing phone numbers of friends with names as keys

So, tuples are useful for fixed ordered data, while dictionaries are useful for mapping one thing to another.

Not sure why a step works? check your working in Super Tutor

7Prove with the help of an example that the variable
is rebuilt in case of immutable data types.
Show solution
For an immutable data type, if we try to change a value, Python does not modify the existing object; instead, a new object is created.

Example:

```python
s = "Hello"
print(id(s))
s = s + " World"
print(id(s))
```

The string `s` is immutable. When `" World"` is added, the old string is not changed. A new string is created, so the `id()` value changes. This proves that the variable is rebuilt in case of immutable data types.

Not sure why a step works? check your working in Super Tutor

8TypeError occurs while statement 2 is running.
Give reason. How can it be corrected?
>>> tuple1 = (5) #statement 1
>>> len(tuple1) #statement 2
Show solution
`tuple1 = (5)` does not create a tuple. It is treated as an integer because a single-element tuple must have a comma.

So `len(tuple1)` causes a TypeError because `len()` cannot be applied to an integer.

Correct form:

```python
tuple1 = (5,)
print(len(tuple1))
```

Now `tuple1` is a tuple with one element, so `len(tuple1)` will work.

Not sure why a step works? check your working in Super Tutor

1Write 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. [Hint: You may use the function split()]Show solution
```python
# Read email IDs of n students and store them in a tuple
n = int(input("Enter number of students: "))
emails = ()
usernames = ()
domains = ()

for i in range(n):
email = input("Enter email ID: ")
emails = emails + (email,)
username, domain = email.split('@')
usernames = usernames + (username,)
domains = domains + (domain,)

print("Email IDs:", emails)
print("Usernames:", usernames)
print("Domains:", domains)
```

This program stores the email IDs in a tuple, then uses `split('@')` to separate each email into username and domain, and stores them in two new tuples.

Not sure why a step works? check your working in Super Tutor

2Write a program to input 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:

(a) writing a user defined function
(b) using the built-in function
3Write a Python program to find the highest 2 values in a dictionary.
4Write a Python program to create a dictionary from a string.
Note: Track the count of the letters from the string.
Sample string : 'w3resource'
Expected output : {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}
5Write a program to input your friends' names and their Phone Numbers and store them in the dictionary as the key-value pair. Perform the following operations on the dictionary:
a) Display the name and phone number of all your friends
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular friend from the dictionary
d) Modify the phone number of an existing friend
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names
1A bank is a financial institution which is involved in borrowing and lending of money. With advancement 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 initial investigation you are suggested to
- collect a bank's 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 of 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 amount and period for a Fixed Deposit and display its maturity amount for a particular customer.
2Participating in a quiz can be fun as it provides a competitive element. Some educational institutes use it as a tool to measure knowledge level, abilities
3Our 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 of 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?
- 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 of 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.
4Every mode of transport utilises a reservation system to ensure its smooth and efficient functioning. If you analyse 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 sub-systems 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.

Figure 1: Railway reservation system

8 more solved questions in Tuples and Dictionaries

Every remaining exercise is solved step by step in Super Tutor, plus practice quizzes and flashcards for this chapter. Free to start.

Stuck on a step?

Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.

Ask a Doubt Free

Frequently Asked Questions

What are the important topics in Tuples and Dictionaries for CBSE Class 11 Computer Science?
Tuples and Dictionaries covers several key topics that are frequently asked in CBSE Class 11 board exams. Focus on the core concepts listed on this page and practise related questions to build confidence.
How to score full marks in Tuples and Dictionaries — CBSE Class 11 Computer Science?
Understand the core concepts first, then work through the 42 practice questions available for this chapter. Revise formulas and definitions regularly, and use flashcards for quick recall before the exam.
Where can I get free NCERT Solutions for Tuples and Dictionaries Class 11 Computer Science?
This page has free step-by-step NCERT Solutions for every exercise question in Tuples and Dictionaries (CBSE Class 11 Computer Science) — written the way examiners award marks: given, formula, working, answer.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Tuples and Dictionaries chapter — for free.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for CBSE Class 11 Computer Science.