དཔལ་ལྡན་འབྲུག་གཞུང་། ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
Python Coding
January 2024
Class X ICT Curriculum
January 2024
PYTHON
Key stage IV
Class X
DATA STRUCTURES - TUPLE
Key Concept # 8
January 2024
PYTHON
Key stage IV
Class X
Main concepts | Sub - concepts |
Tuple |
|
Concept Overview
January 2024
PYTHON
Key stage IV
Class X
Objectives
January 2024
PYTHON
Key stage IV
Class X
ACTIVITIES
TUPLE
January 2024
PYTHON
Key stage IV
Class X
Understanding Tuple Data Structure
tuple_name = (element1, element2,element3,…)
marks = (30,45.5,50,50.5,’a’)
syntax:
Example
January 2024
PYTHON
Key stage IV
Class X
Characteristics of Tuple
1
Order
Allow duplicate values
Heterogeneous data types
Immutable
Tuple maintains the order of items; the first item put in will be the first one out.
2
Since tuple is indexed, it can have items with the same value.
Tuple can hold different data types (eg. integer, float,string and even other tuples) within same tuple.
Tuple is unchangeable; items cannot be changed, added or removed after the tuple has been created.
3
4
January 2024
PYTHON
Key stage IV
Class X
Demo - Student Information
Create a Python tuple named student representing student information with the following attributes: name, age, and grade. Assign the values "Alice" for name, 17 for age, and 11 for grade. Print the tuple.
1 2 3 4 | # Create a tuple named student student = ("Alice", 17, 11) # Print the tuple print(student) |
Code
('Alice', 17, 11) |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 1 - Temperature in Celsius and Fahrenheit
Write a Python program to create a tuple named temp containing temperature values in Celsius and Fahrenheit. Assign the values (25, 77) to represent 25 degrees Celsius and its corresponding Fahrenheit equivalent. Print the tuple.
1 2 3 4 | # Create a tuple named temp temp = (25, 77) # Print the tuple print(temp) |
Code
(25, 77) |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 2 - Displaying Book Information
Create a Python program to create a tuple named book_info to store information about english novel ‘The Giver’. Include attributes such as title, author, and year of publication. Assign appropriate values and print the tuple.
1 2 3 4 | # Define a tuple named book_info book_info = ("The Giver", "Lois Lowry", 1993) # Print the tuple print(book_info) |
Code
(‘The Giver’, ‘Lois Lowry’, 1993) |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 3 - Check Your Understanding
January 2024
PYTHON
Key stage IV
Class X
Activity 3 - Check Your Understanding
tuple_name = (element1, element2,element3,…)
ans: student_info = ("Alice", 15, "ICT", 67)
False
True
syntax:
January 2024
PYTHON
Key stage IV
Class X
ACTIVITIES
ACCESSING ITEMS OF THE TUPLE
January 2024
PYTHON
Key stage IV
Class X
Accessing Items of the Tuple
Types of accessing element of Tuple
Index
1
Slice Operator (:)
2
January 2024
PYTHON
Key stage IV
Class X
1. Accessing Element using Index
tuple_name=(element1,element2,element3,...)
tuple_name[index_no]
syntax
Indexes value starts from 0 for the first element and value increases sequentially for each subsequent element in the tuple.
Indexes value starts from -1 for the last element and values decreases sequentially moving backward from the end of the Tuple.
Positive indexes
Negative indexes
January 2024
PYTHON
Key stage IV
Class X
Example
Positive index | 0 | 1 | 2 |
school | Motithang HSS | Bajo HSS | Babesa MSS |
Negative index | -3 | -2 | -1 |
Positive Indexing | |
| |
| |
| |
Negative Indexing | |
| |
| |
| |
Code
1 | school=(“Motithang HSS”, ”Bajo HSS”, “Babesa MSS”) |
school[0]
school[1]
school[2]
Motithang HSS
Bajo HSS
Babesa HSS
Motithang HSS
school[-1]
school[-2]
school[-3]
Babesa HSS
Bajo HSS
January 2024
PYTHON
Key stage IV
Class X
Demo 1 - Displaying Even Number from Tuple
Write a Python program using the tuple given below to display even number from the tuple using positive and negative indexing.
even_num= (100, 102, 104, 106, 108, 110, 112, 118)
#displaying even number at index 0 and 7
print(even_num[0])
print(even_num[7])
January 2024
PYTHON
Key stage IV
Class X
Cont
even_num= (100, 102, 104, 106, 108, 110, 112, 118)
b. Use a for loop to display all elements from the tuple.
#Traversing through Tuple for loop
for x in range(8):
print(even_num[x],end=",")
c. Implement a while loop to display elements until reaching 112.
#Traversing through Tuple using while loop until element 112
print()
x = 0
while even_num[x]!=112:
print(even_num[x],end=",")
x+=1
100 118 100,102,104,106,108,110,112,118, 100,102,104,106,108,110, |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 1 - Displaying Employee Name from Tuple
Write a Python program to create a tuple named emp_name containing employee name: Pema, Subba, Karma, Tawjay, Karsel, and Timsina. Perform the following questions.
January 2024
PYTHON
Key stage IV
Class X
Activity 1 - Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 | emp_name=("Pema","Subb","karma","Tawjay","Karsel","Timsina") #Displaying Tawjay and Timsina using -ve indexing print(emp_name[-3]) print(emp_name[-1]) #Traversing through Tuple for loop for x in range(len(emp_name)): print(emp_name[x],end=",") print() #Traversing through Tuple Karma till Timsina x=2 while x < len(emp_name): print(emp_name[x],end=",") x +=1 |
Code
Tawjay Timsina Pema,Subb,karma,Tawjay,Karsel,Timsina karma,Tawjay,Karsel,Timsina, |
Output
January 2024
PYTHON
Key stage IV
Class X
2. Accessing Element using Slice Operator
tuple_name[start : end : Step]
Slicing in tuple is used to access a range of elements in it.
syntax
It indicates the index where slice has to Start. The default value is 0.
It indicates the index where slice has to End. The default value is length of the List.
it refers to an incremental value. The default value is 1.
January 2024
PYTHON
Key stage IV
Class X
Example
1 2 | odd_num=(1,3,5,7,9,11,13,15,17,19,21,23,25,27,29) print(odd_num[1:13:2]) |
Code
(3, 7, 11, 15, 19, 23) |
Output
Output will be starting from the element at index 1,up to, but not including, the element at index 13. It will select every second element within this range.
January 2024
PYTHON
Key stage IV
Class X
Demo 2 - Displaying Student Marks from Tuple
Create a Python program that accomplishes the following tasks:
40, 45, 34, 56, 57, 78, 23, 48, 67, 90, 91, 88 and 99
#Define the tuple 'marks' with the given marks
marks = (40,45,34,56,57,78,23,48,67,90,91,88,99)
b. Access following marks from the tuple: 45, 34, 56, 57 and 78 using slice operator.
#Access marks 45, 34, 56, 57, and 78 using slice operator
selected_marks = marks[1:6]
print("Selected marks:\n", selected_marks)
January 2024
PYTHON
Key stage IV
Class X
Cont.
c. Used negative index to access all the marks from tuple, except elements of index 1 and 2.
#Use negative index to access all marks except elements #at index 1 and 2
all_except_1_and_2 = marks[-11:]
print("All marks except elements at index 1 and 2:\n", all_except_1_and_2)
d. Access all the elements of even index from the tuple using slice operator.
# Access all elements of even index using slice operator
even_index_marks = marks[::2]
print("Marks at even indices:\n", even_index_marks)
January 2024
PYTHON
Key stage IV
Class X
Demo 2 - Solution
Selected marks: (45, 34, 56, 57, 78) All marks except elements at index 1 and 2: (34, 56, 57, 78, 23, 48, 67, 90, 91, 88, 99) Marks at even indices: (40, 34, 57, 23, 67, 91, 99) |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 2 - Displaying First Quarter Month of Year
Write a Python program to create tuple named months containing the names of all the months. Using slice operators, print the first quarter of the year.
Tell the answer……………………………….
January 2024
PYTHON
Key stage IV
Class X
Activity 3 - Displaying Last Vowels
Write a Python Program to create a tuple named vowels containing the vowels of the english alphabet. Access and print the last vowel in the tuple.
Answer ????????????????????
January 2024
PYTHON
Key stage IV
Class X
Activity 4 - Displaying Age between 20 and 30
Write a Python Program to print the ages of people who are between 20 and 30 years old using slice operators using the tuple given below:
ages = (25, 30, 18, 22, 35, 28, 20, 31, 29, 27)
Home activity …………………
January 2024
PYTHON
Key stage IV
Class X
ACTIVITIES
TUPLE METHODS
January 2024
PYTHON
Key stage IV
Class X
Tuple Methods
SL# | Method | Description | Syntax |
| | | |
| | | |
| | | |
1
2
3
count()
index()
len()
Returns the number of times a specified value occurs in a tuple.
Searches the tuple for a specified value and returns the position of where it was found.
used to determine the length or the number of elements in a tuple
tuple_name.count(element)
tuple_name.index(element)
len(tuple_name)
Python has a set of built-in methods that can be used to manipulate items in the tuple. Here are some of the common tuple methods in Python:
January 2024
PYTHON
Key stage IV
Class X
Set Methods(cont.)
SL# | Method | Description | Syntax |
| | | |
| | | |
| | | |
4
5
min()
max()
used to find the minimum value occurs in a tuple
used to find the maximum value occurs in a tuple.
min(tuple_name)
max(tuple_name)
sum()
Return the sum of all elements in the tuple
result = sum(tuple_name)
6
January 2024
PYTHON
Key stage IV
Class X
Demo 1 - Analyzing the Student Data
Write a Python program that analyzes student data. Given two tuples:
names = ("Dawa", "Pema", "Dorji", "Pema")
marks = (45, 56, 78, 73)
Your program should perform the following tasks:
# Task 1: Calculate and display the average mark
average_mark = sum(marks) / len(marks)
print("Average mark:", average_mark)
2. Determine and print the highest mark achieved among the students.
# Task 2: Determine and print the highest mark achieved
highest_mark = max(marks)
print("Highest mark:", highest_mark)
January 2024
PYTHON
Key stage IV
Class X
Cont.
3. Determine and display the lowest mark among the students.
# Task 4: Determine and display the lowest mark
lowest_mark = min(marks)
print("Lowest mark:", lowest_mark)
Average mark: 63.0 Highest mark: 78 Lowest mark: 45 |
Output
January 2024
PYTHON
Key stage IV
Class X
Activity 1 - English Mark Analysis
Chimi Yoezer Wangmo has been tasked with presenting the result analysis of english marks of 2024 midterm examination. The dataset of english marks is as follows:
english_marks=(23,45,34,56,89,67,89,45,56,78,90)
Using Python tuple methods, perform the following analyses:
January 2024
PYTHON
Key stage IV
Class X
Activity 1 - Solution
1 2 3 4 5 6 7 8 9 10 11 | english_marks=(23,45,34,56,89,67,89,45,56,78,90) #Task 1:total number of students who scored 45 marks mode_45 = english_marks.count(45) print("Total student who score 45:",mode_45) #Task 2: Find the total number of students print("Total Student:",len(english_marks)) # Task 3: Identify the minimum and maximum marks min_marks = min(english_marks) max_marks = max(english_marks) print("Minimum mark:",min_marks) print("Maximum mark:",max_marks) |
Total student who score 45: 2 Total Student: 11 Minimum mark: 23 Maximum marks: 90 |
Output
Code
January 2024
PYTHON
Key stage IV
Class X
Activity 2 - Calculating Total of Expenditure
Tashi went shopping for stationery before starting school. He bought various items with their respective costs: books for Nu.750, a geometry set for Nu.240, pens for Nu.100, a pencil for Nu.20, celotrip for Nu.115, and a calculator for Nu.650.
Write the Python program using the tuple to calculate and print the total expenses for the Tashi’s stationery shopping.
Solve it ………………….
January 2024
PYTHON
Key stage IV
Class X
Activity 3 - Average of the First 5 Natural Numbers
Write a Python program to find the average of the first 5 natural numbers from the tuple.
Solving time ………………………………….
January 2024
PYTHON
Key stage IV
Class X
Activity 4 - Calculating Average Age of Female Classmates
Denka is in grade 10 and she's organizing a class party. She wants to know the average age of the girls in her class so she can plan appropriate activities. She asked her female classmates for their ages and received the following data: 14, 16, 14, 17, 18, 16, 16, 15, 15, 14, 14, 17, 18, 14, 14, and 15 years old. Can you help Denka write a Python program to find the average age of her female classmates? The ages should be stored in a tuple.
Show your work …………………………….
January 2024
PYTHON
Key stage IV
Class X
Activity 5 - Fetching Location of Number
Dorji and his classmates are organizing a quiz competition for their grade 10 class. Each question in the quiz is assigned a unique number, and these numbers are stored in a tuple as follows:
unique_numbers = (101, 205, 309, 415, 520, 625, 730)
Dorji needs a tool to quickly find the position of each question based on its number in the list of quiz questions. He decides to use a Python program to assist him in this task. Write a Python program to help Dorji by allowing him to input a question number and then determining its position in the list of quiz questions.
Your solution time ……………………………
January 2024
PYTHON
Key stage IV
Class X
Activity 6 - Login system
Write a Python program to receive user input for User_ID and password. Validate the provided User_ID and password against predefined values stored in a tuple. If both conditions are true, display the message "Welcome to your page"; otherwise, show the message "Sorry, you entered incorrect User_ID and Password."
Show your work …………………………..
January 2024
PYTHON
Key stage IV
Class X
Difference between Data Structures
List is mutable
Tuple is immutable
Set is mutable
Dictionary is mutable
list
tuple
set
dictionary
01
Mutable
Defined using square brackets []
Defined using parentheses ()
Defined using curly braces {}
Defined using curly braces {} with key-value pairs separated by colons :
list
tuple
set
dictionary
02
Syntax
Elements are stored in a specific sequence and can be accessed using indices.
Elements are stored in a specific sequence and can be accessed using indices.
Elements are not stored in any particular sequence, and there is no concept of indexing. Set is unordered
Elements are not stored in any specific sequence, and there is no concept of indexing. Dictionary is unordered.
list
tuple
set
dictionary
03
Ordered
January 2024
PYTHON
Key stage IV
Class X
Difference between Data Structures(cont.)
Suitable for storing collections of items where the order matters and modification of elements is required.
Ideal for representing fixed collections of items, function arguments, and situations where data integrity is important.
Suitable for storing unique elements and performing set operations such as union, intersection, and difference.
Effective for mapping keys to values and for situations where fast lookup by key is required.
list
tuple
set
dictionary
04
Use cases
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
my_set = {1, 2, 3}
my_dict = {'a': 1, 'b': 2, 'c': 3}
list
tuple
set
dictionary
05
Example
January 2024
PYTHON
Key stage IV
Class X
Key Points
January 2024
PYTHON
Key stage IV
Class X
Key Points
January 2024
PYTHON
Key stage IV
Class X
བཀྲིན་ཆེ།
THANK YOU
January 2024
PYTHON
Key stage IV
Class X