DI02032011 - Python Programming
DI02032011 - Python Programming
Laboratory Manual
Python Programming
(DI02032011)
DTE’s Vision:
● To provide globally competitive technical education;
● Remove geographical imbalances and inconsistencies;
● Develop student friendly resources with a special focus on girls’ education and
support to weaker sections;
● Develop programs relevant to industry and create a vibrant pool of technical
professionals.
Institute’s Vision:
To develop technically proficient and ethically sound diploma engineers
contributing to industry and society needs.
Institute’s Mission:
Institute Government Polytechnic, Gandhinagar strives,
❖ M1: To impart quality technical education.
❖ M2: To shape students towards sensitizing in ethical values and contributing
in nature.
❖ M3: To familiarize students with the world of work.
Department’s Vision:
To develop technically sound and ethically strong diploma Information and
Communication Technology engineers contributing to industry and society.
Department’s Mission:
❖ M1: To develop students’ proficiency in the field of Information and
Communication Technology engineering to serve the industry and society.
❖ M2: To focus on inculcating ethical values and contributory approach.
❖ M3: To provide effective teaching learning to students through continuous
faculty development.
Python Programming (DI02032011)
Python Programming (DI02032011)
Certificate
Place: …………………..
Date: …………………..
Preface
The primary aim of any laboratory/Practical/field work is enhancement of required skills as well as
creative ability amongst students to solve real time problems by developing relevant competencies
in psychomotor domain. Keeping in view, GTU has designed competency focused outcome-based
curriculum -2021 (COGC-2021) for Diploma engineering programmes. In this more time is allotted
to practical work than theory. It shows importance of enhancement of skills amongst students and
it pays attention to utilize every second of time allotted for practical amongst Students, Instructors
and Lecturers to achieve relevant outcomes by performing rather than writing practice in study
type. It is essential for effective implementation of competency focused outcome- based Green
curriculum-2021. Every practical has been keenly designed to serve as a tool to develop & enhance
relevant industry needed competency in each and every student. These psychomotor skills are very
difficult to develop through traditional chalk and board content delivery method in the classroom.
Accordingly, this lab manual has been designed to focus on the industry defined relevant outcomes,
rather than old practice of conducting practical to prove concept and theory.
By using this lab manual, students can read procedure one day in advance to actual performance
day of practical experiment which generates interest and also, they can have idea of judgement of
magnitude prior to performance. This in turn enhances predetermined outcomes amongst
students. Each and every Experiment /Practical in this manual begins by competency, industry
relevant skills, course outcomes as well as practical outcomes which serve as a key role for doing
the practical. The students will also have a clear idea of safety and necessary precautions to be
taken while performing experiment.
This manual also provides guidelines to lecturers to facilitate student-centered lab activities for each
practical/experiment by arranging and managing necessary resources in order that the students
follow the procedures with required safety and necessary precautions to achieve outcomes. It also
gives an idea that how students will be assessed by providing Rubrics.
Although we try our level best to design this lab manual, but always there are chances of
improvement. We welcome any suggestions for improvement.
Python Programming (DI02032011)
______________________________________________________________________________________
1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics, science and
engineering fundamentals and engineering specialization to solve the engineering problems.
2. Problem analysis: Identify and analyse well-defined engineering problems using codified
standard methods.
4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.
7. Life-long learning: Ability to analyze individual needs and engage in updating in the context of
technological changes in field of engineering.
Python Programming (DI02032011)
______________________________________________________________________________________
A) B)
1 *****
12 ****
123 ***
1234 **
12345 *
8. Create a User-defined function to print the
√
Fibonacci series of 0 to N numbers. (Where N
is an integer number and passed as an
argument)
9.
a) Develop a User-defined function to find the
√
factorial of a given number.
b) Write a Program using the function that
reverses the entered
value.
Write a Program that determines whether a
√
10. given number is an ‘Armstrong number’ or a
palindrome using a user-defined function.
The following industry relevant skills are expected to be developed in the students by performance of
experiments of this course.
1. Organize the work in the group and make record of all observations.
2. Students shall develop maintenance skill as expected by industries.
3. Student shall attempt to develop related hand-on skills and build confidence.
4. Student shall develop the habits of evolving more ideas, innovations, skills etc.
5. Student shall refer technical magazines and data books.
6. Student should develop habit to submit the practical on date and time.
7. Student should well prepare while submitting write-up of exercise.
Python Programming (DI02032011)
______________________________________________________________________________________
6.
a) Write a Python program to print 1 to 10
numbers using loops.
b) Write a Program to show whether the
entered number is prime or not
7. Write a Program to display the following
patterns.
A) B)
1 *****
12 ****
123 ***
1234 **
12345 *
Python Programming (DI02032011)
______________________________________________________________________________________
9.
a) Develop a User-defined function to find the
factorial of a given number.
b) Write a Program using the function that
reverses the entered
value.
Write a Program that determines whether a
10. given number is an ‘Armstrong number’ or a
palindrome using a user-defined function.
F. Prerequisite Theory:
An introduction to Algorithm
What is Algorithm?
The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”. Therefore, Algorithm refers to a set of rules/instructions that step-by-step
define how a work is to be executed upon in order to get the expected results.
1|Page
Python Programming (DI02032011)
______________________________________________________________________________________
It can be understood by taking an example of cooking a new recipe. To cook a new recipe, one
reads the instructions and steps and execute them one by one, in the given sequence. The result thus
obtained is the new dish cooked perfectly. Similarly, algorithms help to do a task in programming to get
the expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that can
be implemented in any language, and yet the output will be the same, as expected.
What is a Flowchart?
2|Page
Python Programming (DI02032011)
______________________________________________________________________________________
1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A
pause/halt is generally used in a program logic under some error conditions. Terminal is the
first and last symbols in the flowchart.
4. Decision Diamond symbol represents a decision point. Decision based operations such as
yes/no question or true/false are indicated by diamond in flowchart.
5. Connectors: Whenever flowchart becomes complex or it spreads over more than one
page, it is useful to use connectors to avoid any confusions. It is represented by a circle.
6. Flow lines: Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among different symbols
of flowchart.
3|Page
Python Programming (DI02032011)
______________________________________________________________________________________
7. Subroutine: This symbol is used for user defined function or sub program.
8. Page Break: When flowchart does not fit into single page then page break and page
continue symbols are used.
Page Break symbol indicate break in current page.
9. Page Continue
Page continue symbol indicate continue flowchart in another page.
Example : Draw a flowchart to input two numbers from user and display the largest of two numbers
4|Page
Python Programming (DI02032011)
______________________________________________________________________________________
G. References:
1. [Link]
H. Flow Chart/Code:
i. Find the sum of two given numbers.
5|Page
Python Programming (DI02032011)
______________________________________________________________________________________
6|Page
Python Programming (DI02032011)
______________________________________________________________________________________
7|Page
Python Programming (DI02032011)
______________________________________________________________________________________
8|Page
Python Programming (DI02032011)
______________________________________________________________________________________
I. Assessment Scheme :
Criteria Assessment scale Obtained points
Technical Skills: 5 point - Demonstrates mastery of technical skills and can
use them to solve complex problems.
4 point - Demonstrates proficiency in technical skills and
can use them to solve simple problems.
3 point - Demonstrates basic competency in technical skills
but struggles with more complex tasks.
2 point - Demonstrates limited competency in technical
skills and requires significant assistance.
1 point- Does not demonstrate competency in technical
skills.
Work Quality: 5 point - Produces work that is of exceptional quality and
meets all requirements.
4 point - Produces work that is of good quality and meets
most requirements.
3 point - Produces work that meets some requirements but
requires revision or improvement.
2 point - Produces work that does not meet most
requirements and requires significant revision or
improvement.
1 point - Does not produce work that meets any
requirements.
Collaboration: 5 point - Works effectively with partners or in a group
setting, communicates well, and contributes equally.
4 point - Works well with partners or in a group setting,
communicates effectively, and contributes fairly.
3 point - Works adequately with partners or in a group
setting, communicates somewhat effectively, and
contributes unequally.
2 point - Struggles to work with partners or in a group
setting, communicates poorly, and does not contribute
equally.
1 point - Does not work well with partners or in a group
setting, communicates poorly, and does not contribute.
Total : /20
Sign with date:
9|Page
Python Programming (DI02032011)
______________________________________________________________________________________
10 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.2:
a) Write a Program to print your name, mobile number, and date of birth.
b) Develop a Program to identify data-types in python.
A. Objective: Program to display message on screen.
F. Prerequisite Theory:
When you run this program, it will print the message "Hello, world!" to the screen. You can modify
the message to display any other text that you want.
Python Code:
print("Hello, world!")
Output:
Hello, world!
Data Types:
11 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Every value in Python has a data type. Since everything is an object in Python programming, data
types are classes, and variables are instance (object) of these classes. There are various data types
in Python. Some of the important types are listed below.
DATA TYPES IN PYTHON
• Python Numbers
• Python List
• Python Tuple
• Python Strings
• Python Set
• Python Dictionary
12 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Raw String r"raw \n string" [ Used when we want to have a string that contains
backslash and don’t want it to be treated as an escape character.]
Unicode ं
u"\u0938\u0902\u0917\u0940\u0924\u093E" will print 'सग
string ं तं '
13 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Python Tuple
Tuple is an ordered sequences of items same as list. The only difference is that
tuples are immutable. Tuples once created cannot be modified.
Tuples are used to write-protect data and are usually faster than list as it cannot
change dynamically. It is defined within parentheses () where items are
separated by commas
>>> t = (50,'Learning is fun', 1+3j, 45.67) # Can store mixed data types
14 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Python Code:
Output:
<class 'int'>
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No /Components/Trainer
. kit
15 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
16 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them
to solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical
skills and requires significant assistance.
1 point- Does not demonstrate competency in technical
skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most
requirements.
Work Quality: 3 point - Produces work that meets some requirements but requires
revision or improvement.
2 point - Produces work that does not meet most requirements and
requires significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting,
communicates poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools,
Initiative: but requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools,
requires significant guidance, and produces work that does not meet
most requirements.
1 point - Does not take initiative to explore new concepts and tools,
requires constant guidance, and does not meet any requirements.
Total : /20
Sign with date:
17 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
18 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.3:
a) Create a Program to read three numbers from the user and find the average of the
numbers.
b) Develop a Program that can calculate simple interest and compound interest on
given data.
c) Write a Program to convert temperature from Fahrenheit to Celsius unit using eq:
C=(F- 32)/1.8
A. Objective: Program to read three numbers from the user and find the average of the
numbers.
B. Expected Program Outcomes (POs):
a. Basic knowledge: Apply knowledge of basic mathematics, sciences, and basic
engineering to solve the broad-based Computer engineering problem.
b. Discipline knowledge: Apply Computer engineering discipline - specific knowledge
to solve core computer engineering related problems
c. Experiments and practice: Plan to perform experiments and practices to use the
results to solve broad-based Computer engineering problems.
d. Individual and team work: Function effectively as a leader and team member in
diverse/ multidisciplinary teams.
e. Life-long learning: Engage in independent and life-long learning activities in the
context of technological changes in the computer engineering field and allied
industry.
F. Prerequisite Theory:
A. Create a Program to read three numbers from the user and find the average of the
numbers.
19 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
In Program To find the average of three numbers, you need to add up the three numbers and
then divide the sum by 3. Here's the logic in pseudocode:
1. Take three numbers as input from the user
2. Add the three numbers together
3. Divide the sum by 3 to get the average
4. Print the average
B. Develop a Program that can calculate simple interest and compound interest on given
data.
Simple Interest = (P * R * T) / 100
Where P is the principal amount
R is the rate of interest per annum
T is the time duration in years
Here is the logic in pseudocode to calculate Simple Interest:
1. Take the principal amount, rate of interest, and time duration as input from the user
2. Calculate the simple interest using the formula: (P * R * T) / 100
3. Print the simple interest.
Compound interest is calculated based on the principal amount, rate of interest, time period,
and the number of times the interest is compounded per year. The formula to calculate
compound interest is:
Compound Interest = P * (1 + (R / N)) ^ (N * T) - P
where, P is the principal amount
R is the annual interest rate
N is the number of times the interest is compounded per year
T is the time duration in years
Here's the logic in pseudocode to calculate compound interest:
1. Take the principal amount, rate of interest, time duration, and number of times interest is
compounded as input from the user
2. Calculate the compound interest using the formula: P * (1 + (R / N)) ^ (N * T) - P
3. Print the compound interest
C. Write a Program to convert temperature from Fahrenheit to Celsius unit using eq: C=(F-
32)/1.8
To convert a temperature from Celsius to Fahrenheit, you can use the formula:
F = (C * 9/5) + 32
Here's the logic in pseudocode to convert Celsius to Fahrenheit:
1. Take the temperature in Celsius as input from the user
2. Convert the temperature from Celsius to Fahrenheit using the formula: F = (C * 9/5) + 32
3. Print the temperature in Fahrenheit
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
20 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
21 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
b) Develop a Program that can calculate simple interest and compound interest on
given data.
22 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
23 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Total : /20
Sign with date:
24 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.4:
a) Identify whether the scanned number is even or odd and print an appropriate
message.
b) Create a Program to find a maximum number among the given three numbers.
A. Objective: Program to read three numbers from the user and check it is odd or even and
find maximum of given three numbers.
B. Expected Program Outcomes (POs):
a. Basic knowledge: Apply knowledge of basic mathematics, sciences, and basic
engineering to solve the broad-based Computer engineering problem.
b. Discipline knowledge: Apply Computer engineering discipline - specific knowledge
to solve core computer engineering related problems
c. Experiments and practice: Plan to perform experiments and practices to use the
results to solve broad-based Computer engineering problems.
d. Individual and team work: Function effectively as a leader and team member in
diverse/ multidisciplinary teams.
e. Life-long learning: Engage in independent and life-long learning activities in the
context of technological changes in the computer engineering field and allied
industry.
Here's an example:
25 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
In this example, the condition is "x > 5". Since the value of "x" is 10, the condition is True, so
the code inside the "if" block will be executed, and the output will be "x is greater than 5".
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
26 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
b) Create a Program to find a maximum number among the given three numbers.
I. References:
1. [Link]
2. [Link]
27 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Total : /20
Sign with date:
28 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.5:
Develop a Program to demonstrate the basic functionalities of a standard calculator.
A. Objective: Program to Develop a Program to demonstrate the basic functionalities of a
standard calculator.
B. Expected Program Outcomes (POs):
a. Basic knowledge: Apply knowledge of basic mathematics, sciences, and basic
engineering to solve the broad-based Computer engineering problem.
b. Discipline knowledge: Apply Computer engineering discipline - specific knowledge
to solve core computer engineering related problems
c. Experiments and practice: Plan to perform experiments and practices to use the
results to solve broad-based Computer engineering problems.
d. Individual and team work: Function effectively as a leader and team member in
diverse/ multidisciplinary teams.
e. Life-long learning: Engage in independent and life-long learning activities in the
context of technological changes in the computer engineering field and allied
industry.
.
.
.
else:
# code to be executed if condition is False
29 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Here's an example:
# if-elif statement example
letter = "A"
if letter == "B":
print("letter is B")
else:
print("letter isn't A, B or C")
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
30 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
31 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical
skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most
requirements.
Work Quality: 3 point - Produces work that meets some requirements but requires revision
or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1
5 point
point- Does not produce
- Works work that
effectively withmeets any requirements.
partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting,
communicates poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date:
32 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.6:
a) Write a Python program to print 1 to 10 numbers using loops.
b) Write a Program to show whether the entered number is prime or not.
A. Objective: Program to demonstrate the use of loop.
B. Expected Program Outcomes (POs):
a. Basic knowledge: Apply knowledge of basic mathematics, sciences, and basic
engineering to solve the broad-based Computer engineering problem.
b. Discipline knowledge: Apply Computer engineering discipline - specific knowledge
to solve core computer engineering related problems
c. Experiments and practice: Plan to perform experiments and practices to use the
results to solve broad-based Computer engineering problems.
d. Individual and team work: Function effectively as a leader and team member in
diverse/ multidisciplinary teams.
e. Life-long learning: Engage in independent and life-long learning activities in the
context of technological changes in the computer engineering field and allied
industry.
33 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
You can use the break keyword to exit the loop prematurely and the continue keyword to
skip to the next iteration of the loop without executing the remaining code in the current
iteration.
In Python, a while loop is a control flow statement that allows you to execute a block of code
repeatedly while a specified condition is true. The general syntax for a while loop is:
while condition:
# code to be executed while condition is True
Here, condition is a Boolean expression that is evaluated before each iteration of the loop. If
the condition is True, the code inside the loop body is executed. Once the loop body has
executed, the condition is re-evaluated and the loop continues executing as long as the
condition remains True.
You can use the break keyword to exit the loop prematurely and the continue keyword to
skip to the next iteration of the loop without executing the remaining code in the current
iteration.
For example, the following code demonstrates a while loop that repeatedly prompts the user
to enter a number until a valid number is entered:
while True:
try:
num = int(input("Enter a number: "))
break
except ValueError:
print("Invalid number. Please try again.")
Here, the loop continues executing as long as the user enters an invalid number. Once a valid
number is entered, the loop is exited using the break keyword.
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
34 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
35 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
36 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date:
37 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
38 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
print()
Output:
*****
*****
*****
*****
*****
Using range function with step:
You can use the range function with a step to print patterns of numbers, letters, and other
characters. Here's an example to print a pattern of numbers:
n=5
for i in range(1, n+1):
print(str(i)*i)
Output:
1
22
333
4444
55555
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
40 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
41 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
B)
*****
****
***
**
*
I. References:
1. [Link]
2. [Link]
42 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
43 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
44 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
F. Prerequisite Theory:
In Python, a user-defined function is a block of reusable code that performs a specific task.
A user-defined function can be created using the def keyword, followed by the name of the
function and its parameters enclosed in parentheses. The body of the function is indented
below the def statement.
Here is the general syntax for creating a user-defined function in Python:
def function_name(parameter1, parameter2, ...):
# function body
# statements
return value
45 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
The parameter1, parameter2, and so on, are optional parameters that can be passed to the
function. These parameters are used to pass data to the function for processing. The return
statement is optional and is used to return a value from the function.
When a function is called, the arguments passed to the function are assigned to the
parameters in the function definition. The function then executes the statements in its body,
and if a return statement is encountered, the function returns the value specified by the
return statement.
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence
relation
Fn = Fn-1 + Fn-2
with seed values
F0 = 0 and F1 = 1.
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
46 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
47 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
48 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.9:
a) Develop a User-defined function to find the factorial of a given number.
b) Write a Program using the function that reverses the entered value.
49 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
The parameter1, parameter2, and so on, are optional parameters that can be passed to the
function. These parameters are used to pass data to the function for processing. The return
statement is optional and is used to return a value from the function.
When a function is called, the arguments passed to the function are assigned to the
parameters in the function definition. The function then executes the statements in its body,
and if a return statement is encountered, the function returns the value specified by the
return statement.
A) To find the factorial of a given number
The Factorial of a whole number 'n' is defined as the product of that number with every whole
number less than or equal to 'n' till 1. For example, the factorial of 4 is 4 × 3 × 2 × 1, which is
equal to 24.
B) To reverses the entered value.
First, the remainder of the num divided by 10 is stored in the variable digit. Now, the digit
contains the last digit of num, i.e. 4.
Digit is then added to the variable reversed after multiplying it by 10. Multiplication by 10
adds a new place in the reversed number. One-th place multiplied by 10 gives you tenth
place, tenth gives you hundredth, and so on. In this case, reversed_num contains 0 * 10 + 4
= 4.
num is then divided by 10 so that now it only contains the first three digits: 123.
After second iteration, digit equals 3, reversed equals 4 * 10 + 3 = 43 and num = 12.
After third iteration, digit equals 2, reversed equals 43 * 10 + 2 = 432 and num = 1.
After fourth iteration, digit equals 1, reversed equals 432 * 10 + 1 = 4321 and num = 0.
Now num = 0, so the test expression num != 0 fails and while loop exits. reversed already
contains the reversed number 4321.
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
50 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
51 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
b) Write a Program using the function that reverses the entered value.
I. References:
1. [Link]
2. [Link]
52 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
53 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
54 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
55 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
56 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
57 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
58 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.11:
a) Write a Program to find the length of a string.
b) Write a Program to reverse words in a given sentence.
c) Write a Program to check if a substring is present in a given string.
d) Write a Program to count and display the number of vowels, consonants,
uppercase, lowercase characters in a string.
A. Objective: Program to demonstrate the use of different string functions and operations.
print(b[2:5])
Output: llo
b = "Hello, World!"
print(b[-5:-2])
Output:orl
Split:
The split() method returns a list where the text between the specified separator becomes the
list items.
a = "Hello, World!"
b = [Link](",")
print(b)
Output: ['Hello', ' World!']
Python has a set of built-in methods that you can use on strings.
Function Name Description
Converts the first character of the string to a capital (uppercase)
capitalize()
letter
casefold() Implements caseless string matching
center() Pad the string with the specified character.
count() Returns the number of occurrences of a substring in the string.
encode() Encodes strings with the specified encoded scheme
endswith() Returns “True” if a string ends with the given suffix
Specifies the amount of space to be substituted with the “\t”
expandtabs()
symbol in the string
find() Returns the lowest index of the substring if it is found
format() Formats the string for printing it to console
format_map() Formats specified values in a string using a dictionary
Returns the position of the first occurrence of a substring in a
index()
string
Checks whether all the characters in a given string is alphanumeric
isalnum()
or not
isalpha() Returns “True” if all characters in the string are alphabets
isdecimal() Returns true if all characters in a string are decimal
isdigit() Returns “True” if all characters in the string are digits
isidentifier() Check whether a string is a valid identifier or not
islower() Checks if all characters in the string are lowercase
isnumeric() Returns “True” if all characters in the string are numeric characters
Returns “True” if all characters in the string are printable or the
isprintable()
string is empty
Returns “True” if all characters in the string are whitespace
isspace()
characters
istitle() Returns “True” if the string is a title cased string
isupper() Checks if all characters in the string are uppercase
join() Returns a concatenated String
ljust() Left aligns the string according to the width specified
60 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
61 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
62 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
63 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
64 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
65 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
66 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
A. Objective: Program to demonstrate the use of different list methods and operations.
67 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Method Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the current list
index() Returns the index of the first element with the specified value
insert() Adds an element at the specified position
pop() Removes the element at the specified position
remove() Removes the item with the specified value
reverse() Reverses the order of the list
sort() Sorts the list
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
68 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
69 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
70 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
71 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most
requirements.
Work Quality: 3 point - Produces work that meets some requirements but requires revision
or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point
5 point- Does not produce
- Works work that
effectively withmeets any requirements.
partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting,
communicates poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
72 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.13:
a) Given a List saved in variable: a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. Write one line
of Python that takes this list and makes a new list that has only the even elements of
this list in it.
b) Create a List containing the square of all odd numbers from range 1 to 10.
c) Create a List of prime and non-prime numbers in range 1 to 50.
d) To find the smallest and largest element in a given list.
Without list comprehension you will have to write a for statement with a conditional test
inside:
73 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
for x in fruits:
if "a" in x:
[Link](x)
print(newlist)
Output : ['apple', 'banana', 'mango']
With list comprehension you can do all that with only one line of code:
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
newlist = [x for x in fruits if "a" in x]
print(newlist)]
Output : ['apple', 'banana', 'mango']
newlist = [expression for item in iterable if condition == True]
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
74 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
b) Create a List containing the square of all odd numbers from range 1 to 10.
75 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
76 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
77 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
78 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Practical No.14:
a) Write a Program to demonstrate some useful set functions and operations.
b) Write a Program to demonstrate some useful Tuple functions and operations.
A. Objective: Program to demonstrate the use of set and tuple functions and operations.
Python Set:
Sets are used to store multiple items in a single variable. A set is a collection which is
unordered, unchangeable, and unindexed. Sets are written with curly brackets. Set items are
unordered, unchangeable, and do not allow duplicate values. Sets are unordered, so you
cannot be sure in which order the items will appear. Sets cannot have two items with the
same value.
thisset = {"apple", "banana", "cherry"}
print(thisset)
output : {'cherry', 'apple', 'banana'}
Python has a set of built-in methods that you can use on sets.
79 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Python Tuple:
Tuples are used to store multiple items in a single variable. A tuple is a collection which is
ordered and unchangeable. Tuples are written with round brackets. When we say that tuples
are ordered, it means that the items have a defined order, and that order will not change.
Tuples are unchangeable, meaning that we cannot change, add or remove items after the
tuple has been created. Since tuples are indexed, they can have items with the same value.
thistuple = ("apple", "banana", "cherry", "apple", "cherry")
print(thistuple)
output : ('apple', 'banana', 'cherry', 'apple', 'cherry')
Python has two built-in methods that you can use on tuples.
Method Description
count() Returns the number of times a specified value occurs in a tuple
index() Searches the tuple for a specified value and returns the position of where it was found
Print and attach Your Code along with output with this practical.
G. Resources/Equipment Required
80 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
81 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
82 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
83 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
84 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
Total : /20
Sign with date: ___________
85 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
86 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
F. Prerequisite Theory:
Python Dictionary:
Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is
ordered, mutable (with condition that dictionary values which are of mutable types are changeable
while dictionary values which are of immutable types cannot be changed) and do not allow
duplicates. Dictionaries are written with curly brackets, and have keys and values:
Create and print a dictionary:
87 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
Thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
O/P:
Method Description
items() Returns a list containing a tuple for each key value pair
Returns the value of the specified key. If the key does not exist: insert the key, with the
setdefault()
specified value
G. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No
/Components/Trainer
.
kit
88 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
89 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
90 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
I. References:
1. [Link]
2. [Link]
91 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
J. Assessment Scheme:
Criteria Assessment scale Obtained
points
5 point - Demonstrates mastery of technical skills and can use them to
solve complex problems.
4 point - Demonstrates proficiency in technical skills and can use them to
solve simple problems.
Technical 3 point - Demonstrates basic competency in technical skills but struggles
Skills: with more complex tasks.
2 point - Demonstrates limited competency in technical skills and
requires significant assistance.
1 point- Does not demonstrate competency in technical skills.
5 point - Produces work that is of exceptional quality and meets all
requirements.
4 point - Produces work that is of good quality and meets most requirements.
3 point - Produces work that meets some requirements but requires revision
Work Quality: or improvement.
2 point - Produces work that does not meet most requirements and requires
significant revision or improvement.
1 point - Does not produce work that meets any requirements.
5 point - Works effectively with partners or in a groupsetting,
communicates well, and contributes equally.
4 point - Works well with partners or in a group setting, communicates
effectively, and contributes fairly.
3 point - Works adequately with partners or in a group setting,
Collaboration: communicates somewhat effectively, and contributes unequally.
2 point - Struggles to work with partners or in a group setting, communicates
poorly, and does not contribute equally.
1 point - Does not work well with partners or in a group setting,
communicates poorly, and does not contribute.
5 point - Takes initiative to explore new concepts and tools, goes beyond
requirements, and produces exceptional work.
4 point - Takes initiative to explore some new concepts and tools, meets
requirements, and produces good work.
3 point - Occasionally takes initiative to explore new concepts and tools, but
Initiative: requires guidance and produces work that meets basic requirements.
2 point - Rarely takes initiative to explore new concepts and tools, requires
significant guidance, and produces work that does not meet most
requirements.
1 point - Does not take initiative to explore new concepts and tools, requires
constant guidance, and does not meet any requirements.
92 | P a g e
Python Programming (DI02032011)
______________________________________________________________________________________
93 | P a g e