Tuples and Dictionaries
CBSE · Class 11 · Computer Science
NCERT Solutions for Tuples and Dictionaries — CBSE Class 11 Computer Science.
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
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
- `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
- `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
Because they are ordered, we can access elements by index. For example, the first element is at index , the second at index , 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
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 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
- 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
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 2Show solution
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
# 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
We can accomplish these by:
(a) writing a user defined function
(b) using the built-in function
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}
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
- 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.
- 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.
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 FreeFrequently Asked Questions
What are the important topics in Tuples and Dictionaries for CBSE Class 11 Computer Science?
How to score full marks in Tuples and Dictionaries — CBSE Class 11 Computer Science?
Where can I get free NCERT Solutions for Tuples and Dictionaries Class 11 Computer Science?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Tuples and Dictionaries
Practice Quiz
Test yourself with a quick quiz
Important Questions
Practice with board exam-style questions
Revision Notes
Key points for last-minute revision
Formula Sheet
All formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect visually
Study Plan
Step-by-step plan to ace this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
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.