Tuples and Dictionaries – NCERT Class 11 Computer Science Chapter 10 – Tuple Operations and Dictionary Handling in Python
Introduces tuples as immutable ordered sequences with elements of different data types and demonstrates tuple operations such as concatenation, repetition, membership testing, and slicing. Explains tuple assignment, nested tuples, and the immutability characteristic. Covers dictionaries as mutable mappings of unique keys to values, dictionary creation, accessing items, operations, traversal, methods, and manipulation. Includes practical programs to illustrate dictionary use for data storage, retrieval, and updates.
Tip: 2025: Tuples in set operations for unique data.
Tuple Handling - Programs 10-1 to 10-4 Expanded
Core: Nested, swap, circle func, input max/min.
Program 10-1: Nested Student Records
# Program 10-1
st = ((101,"Aman",98),(102,"Geet",95),(103,"Sahil",87),(104,"Pawan",79))
print("S_No"," Roll_No"," Name"," Marks")
for i in range(0,len(st)):
print((i+1),'\t',st[i][0],'\t',st[i][1],'\t',st[i][2])
Output: S_No Roll_No Name Marks 1 101 Aman 98 2 102 Geet 95 3 103 Sahil 87 4 104 Pawan 79
Program 10-2: Swap Numbers
# Program 10-2
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
print("\nNumbers before swapping:")
print("First Number:",num1)
print("Second Number:",num2)
(num1,num2) = (num2,num1)
print("\nNumbers after swapping:")
print("First Number:",num1)
print("Second Number:",num2)
Output: Enter first:5 Enter second:10 Before:5 10 After:10 5
Program 10-3: Circle Area/Circum
# Program 10-3
def circle(r):
area = 3.14*r*r
circumference = 2*3.14*r
return (area,circumference)
radius = int(input('Enter radius of circle: '))
area,circumference = circle(radius)
print('Area of circle is:',area)
print('Circumference of circle is:',circumference)
Output: Enter radius:5 Area:78.5 Circum:31.4
Program 10-4: Input n Numbers Max/Min
# Program 10-4
numbers = tuple()
n = int(input("How many numbers you want to enter?: "))
for i in range(0,n):
num = int(input())
numbers = numbers +(num,)
print('\nThe numbers in the tuple are:')
print(numbers)
print("\nThe maximum number is:")
print(max(numbers))
print("The minimum number is:")
print(min(numbers))
# Program 10-6
num = int(input("Enter the number of employees whose data to be stored: "))
count = 1
employee = dict()
while count <= num:
name = input("Enter the name of the Employee: ")
salary = int(input("Enter the salary: "))
employee[name] = salary
count += 1
print("\n\nEMPLOYEE_NAME\tSALARY")
for k in employee:
print(k,'\t\t',employee[k])
# Program 10-7
st = input("Enter a string: ")
dic = {}
for ch in st:
if ch in dic:
dic[ch] += 1
else:
dic[ch] = 1
for key in dic:
print(key,':',dic[key])
# Program 10-8
def convert(num):
numberNames = {0:'Zero',1:'One',2:'Two',3:'Three',4:'Four',5:'Five',6:'Six',7:'Seven',8:'Eight',9:'Nine'}
result = ''
for ch in num:
key = int(ch)
value = numberNames[key]
result = result + ' ' + value
return result
num = input("Enter any number: ")
result = convert(num)
print("The number is:",num)
print("The numberName is:",result)
Output: Enter:6512 The number is:6512 The numberName is: Six Five One Two
Tip: 2025: Dicts in config files for apps.
NCERT Exercises - Questions & Answers
Based on full NCERT Chapter 10. Structured like textbook with full questions and detailed answers.
Question 1: Consider the following tuples, tuple1 and tuple2: tuple1 = (23,1,45,67,45,9,55,45) tuple2 = (100,200). Find the output...
Question 2: Consider the following dictionary stateCapital: stateCapital = {"AndhraPradesh":"Hyderabad", "Bihar":"Patna","Maharashtra":"Mumbai", "Rajasthan":"Jaipur"}. Find the output...
Question 7: Prove with the help of an example that the variable is rebuilt in case of immutable data types.
Ans:
t = (1,2,3)
id1 = id(t)
t += (4,)
id2 = id(t) # Different ID: new tuple
Question 8: TypeError occurs while statement 2... Give reason. How can it be corrected? tuple1 = (5) len(tuple1)
Ans:
Reason: (5) is int, not tuple. Correct: tuple1 = (5,); len((5,)) → 1.
Programming Problems
1. Write a program to read email IDs... usernames/domains tuples.
Ans:
emails = tuple()
n = int(input("Num emails: "))
for _ in range(n):
email = input("Email: ")
emails += (email,)
usernames = tuple(email.split('@')[0] for email in emails)
domains = tuple(email.split('@')[1] for email in emails)
print(emails, usernames, domains)
2. Input n students names tuple; Search name.
Ans:
names = tuple()
n = int(input("Num students: "))
for _ in range(n): names += (input("Name: "),)
search = input("Search name: ")
print(search in names)
3. Python program to find highest 2 values in dict.
Ans:
d = {'a':10,'b':20,'c':30,'d':40}
vals = sorted(d.values(), reverse=True)[:2]
print(vals) # [40,30]
4. Create dict from string (char count).
Ans:
s = 'w3resource'
d = {}
for c in s: d[c] = d.get(c,0) + 1
print(d) # {'w':1,'3':1,'r':2,...}
5. Friends names/phone dict; Ops a-f.
Ans:
friends = {}
n = int(input("Num friends: "))
for _ in range(n):
name = input("Name: ")
phone = input("Phone: ")
friends[name] = phone
# a) for k,v in friends.items(): print(k,v)
# b) friends['new'] = '123'
# c) del friends['old']
# d) friends['exist'] = '456'
# e) print('name' in friends)
# f) for k in sorted(friends): print(k, friends[k])
Tip: Practice these for board exams; Focus on outputs and UDF logic.
Quick Revision Notes & Enhanced Mnemonics
Tuples
() commas; Immutable
Mnemonic: "PIC" (Parenthesis Immutable Commas).
Indexing
[0] first; Slice [n:m]
Mnemonic: "FS" (First Slice).
Ops
+ * in [::]
Mnemonic: "+*in Slice".
Methods
len count index min max
Mnemonic: "LCIMMS".
Dicts
{k:v} mutable keys unique
Mnemonic: "MKU" (Mutable Keys Unique).
Dict Methods
keys values items get update
Mnemonic: "KVI GU".
Overall: "Tuple Intro Ops Methods Handle Dict Intro Ops Methods Manip" (T I O M H D I O M M). Flashcards ready.
Interactive Quiz: 10 Updated Questions from Full Chapter
2 attempts on CBSE Class 11 Annual Assessment quizzes
f scored 4/10 on Accountancy (Class 11) Subhash scored 1/10 on Sets and Venn Operations f scored 4/10 on Accountancy (Class 11) Subhash scored 1/10 on Sets and Venn Operations
#1
Accountancy (Class 11) Practice Quiz | CBSE Class 11 Annual Assessment
10 Qs · ~10 min
#2
Sets and Venn Operations Fundamentals — Free CBSE Class 11 Annual Assessment Quiz
10 Qs · ~10 min
#3
Business Studies (Class 11) Practice Quiz | CBSE Class 11 Annual Assessment
10 Qs · ~10 min
#4
Economics (Class 11) Practice Quiz | CBSE Class 11 Annual Assessment
10 Qs · ~10 min
#5
Humanities Subjects Practice Quiz | CBSE Class 11 Annual Assessment
10 Qs · ~10 min
#6
Motion in a Straight Line Practice Quiz | CBSE Class 11 Annual Assessment
10 Qs · ~10 min
#7
Thermodynamic Processes and Laws Advanced Challenge | CBSE Class 11 Annual Assessment