0% found this document useful (0 votes)
24 views67 pages

Python Final Version Course File

The document outlines the vision and mission for a B.Tech program in Software Engineering at JNTU Hyderabad, emphasizing the development of professionals in technology and ethical practices. It details the course structure, including syllabi for various semesters, and provides specific objectives and outcomes for the Python Programming Laboratory. Additionally, it lists program outcomes and specific outcomes, highlighting skills in problem-solving, programming, and project management.

Uploaded by

Shanthi latha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views67 pages

Python Final Version Course File

The document outlines the vision and mission for a B.Tech program in Software Engineering at JNTU Hyderabad, emphasizing the development of professionals in technology and ethical practices. It details the course structure, including syllabi for various semesters, and provides specific objectives and outcomes for the Python Programming Laboratory. Additionally, it lists program outcomes and specific outcomes, highlighting skills in problem-solving, programming, and project management.

Uploaded by

Shanthi latha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON COURSE FILE

Ist YEAR 2022-2023


Vision

 To emerge as a Center of Excellence for producing professionals who shall be the leaders

in technology innovation, entrepreneurship, management and in turn contribute for

advancement of society and human kind.

Mission

 M1: To provide an environment of learning in emerging technologies.

 M2 : To nurture a state of art teaching learning process and R&D culture./li>

 M3: To foster networking with Alumni, Industry, Institutes of repute and other stakeholders

for effective interaction.

 M4: To practice and promote high standards of ethical values through societal

commitment.
R22 [Link]. CE (Software Engineering) Syllabus JNTU Hyderabad

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD


[Link]. in COMPUTER ENGINEERING (SOFTWARE ENGINEERING)
COURSE STRUCTURE, I & II YEAR SYLLABUS (R22 Regulations)

Applicable from AY 2022-23 Batch

I Year I Semester
S. Course Course L T P Credits
No. Code
1. Matrices and Calculus 3 1 0 4
2. Engineering Chemistry 3 1 0 4
3. Programming for Problem Solving 3 0 0 3
4. Basic Electrical Engineering 2 0 0 2
5. Computer Aided Engineering Graphics 1 0 4 3
6. Elements of Computer Science & Engineering 0 0 2 1
7. Engineering Chemistry Laboratory 0 0 2 1
8. Programming for Problem Solving Laboratory 0 0 2 1
9. Basic Electrical Engineering Laboratory 0 0 2 1
Total 12 2 12 20

I Year II Semester
S. Course Course L T P Credits
No. Code
1. Ordinary Differential Equations and Vector Calculus 3 1 0 4
2. Applied Physics 3 1 0 4
3. Engineering Workshop 0 1 3 2.5
4. English for Skill Enhancement 2 0 0 2
5. Electronic Devices and Circuits 2 0 0 2
6. Applied Physics Laboratory 0 0 3 1.5
7. Python Programming Laboratory 0 1 2 2
8. English Language and Communication Skills Laboratory 0 0 2 1
9. IT Workshop 0 0 2 1
Total 10 4 12 20

II YEAR I SEMESTER
Course
S. No. Course Title L T P Credits
Code
1 Digital Electronics 3 0 0 3
2 Data Structures 3 0 0 3
3 Computer Oriented Statistical Methods 3 1 0 4
4 Computer Organization and Architecture 3 0 0 3
5 Object Oriented Programming through Java 3 0 0 3
6 Data Structures Lab 0 0 3 1.5
7 Object Oriented Programming through Java Lab 0 0 3 1.5
8 Gender Sensitization Lab 0 0 2 0
9 Skill Development Course (Data visualization- R 0 0 2 1
Programming/ Power BI)
Total 15 1 10 20
R22 [Link]. CE (Software Engineering) Syllabus JNTU Hyderabad

PYTHON PROGRAMMING LABORATORY

[Link]. I Year II Sem. L T P C


0 1 2 2
Course Objectives:
 To install and run the Python interpreter
 To learn control structures.
 To Understand Lists, Dictionaries in python
 To Handle Strings and Files in Python

Course Outcomes: After completion of the course, the student should be able to
● Develop the application specific codes using python.
● Understand Strings, Lists, Tuples and Dictionaries in Python
● Verify programs using modular approach, file I/O, Python standard library
● Implement Digital Systems using Python
Note: The lab experiments will be like the following experiment examples

Week -1:
1. i) Use a web browser to go to the Python website [Link] This page contains information
about Python and links to Python-related pages, and it gives you the ability to search the Python
documentation.
ii) Start the Python interpreter and type help() to start the online help utility.
2. Start a Python interpreter and use it as a Calculator.
3.
i) Write a program to calculate compound interest when principal, rate and number of periods are
given.
ii) Given coordinates (x1, y1), (x2, y2) find the distance between two points
4. Read name, address, email and phone number of a person through keyboard and print the details.

Week - 2:
1. Print the below triangle using for loop.
5
44
333
2222
11111
2. Write a program to check whether the given input is digit or lowercase character or uppercase
character or a special character (use 'if-else-if' ladder)
3. Python Program to Print the Fibonacci sequence using while loop
4. Python program to print all prime numbers in a given interval (use break)

Week - 3:
1. i) Write a program to convert a list and tuple into arrays.
ii) Write a program to find common values between two arrays.
2. Write a function called gcd that takes parameters a and b and returns their greatest common divisor.
3. Write a function called palindrome that takes a string argument and returnsTrue if it is a palindrome
and False otherwise. Remember that you can use the built-in function len to check the length of a string.

Week - 4:
1. Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted
in ascending order and False otherwise.
2. Write a function called has_duplicates that takes a list and returns True if there is any element that
appears more than once. It should not modify the original list.
R22 [Link]. CE (Software Engineering) Syllabus JNTU Hyderabad

i). Write a function called remove_duplicates that takes a list and returns a new list with only the
unique elements from the original. Hint: they don’t have to be in the same order.
ii). The wordlist I provided, [Link], doesn’t contain single letter words. So you might want to add
“I”, “a”, and the empty string.
iii). Write a python code to read dictionary values from the user. Construct a function to invert its
content. i.e., keys should be values and values should be keys.
3. i) Add a comma between the characters. If the given word is 'Apple', it should become 'A,p,p,l,e'
ii) Remove the given word in all the places in a string?
iii) Write a function that takes a sentence as an input parameter and replaces the first letter of every
word with the corresponding upper case letter and the rest of the letters in the word by
corresponding letters in lower case without using a built-in function?
4. Writes a recursive function that generates all binary strings of n-bit length

Week - 5:
1. i) Write a python program that defines a matrix and prints
ii) Write a python program to perform addition of two square matrices
iii) Write a python program to perform multiplication of two square matrices
2. How do you make a module? Give an example of construction of a module using different geometrical
shapes and operations on them as its functions.
3. Use the structure of exception handling all general purpose exceptions.

Week-6:
1. a. Write a function called draw_rectangle that takes a Canvas and a Rectangle as arguments and
draws a representation of the Rectangle on the Canvas.
b. Add an attribute named color to your Rectangle objects and modify draw_rectangle so that it
uses the color attribute as the fill color.
c. Write a function called draw_point that takes a Canvas and a Point as arguments and draws a
representation of the Point on the Canvas.
d. Define a new class called Circle with appropriate attributes and instantiate a few Circle objects.
Write a function called draw_circle that draws circles on the canvas.
2. Write a Python program to demonstrate the usage of Method Resolution Order (MRO) in multiple
levels of Inheritances.
3. Write a python code to read a phone number and email-id from the user and validate it for
correctness.

Week- 7
1. Write a Python code to merge two given file contents into a third file.
2. Write a Python code to open a given file and construct a function to check for given words present in
it and display on found.
3. Write a Python code to Read text from a text file, find the word with most number of occurrences
4. Write a function that reads a file file1 and displays the number of words, number of vowels, blank
spaces, lower case letters and uppercase letters.

Week - 8:
1. Import numpy, Plotpy and Scipy and explore their functionalities.
2. a) Install NumPy package with pip and explore it.
3. Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
4. Write a program to implement Half Adder, Full Adder, and Parallel Adder
5. Write a GUI program to create a window wizard having two text labels, two text fields and two buttons
as Submit and Reset.
R22 [Link]. CE (Software Engineering) Syllabus JNTU Hyderabad

TEXT BOOKS:
1. Supercharged Python: Take your code to the next level, Overland
2. Learning Python, Mark Lutz, O'reilly

REFERENCE BOOKS:
1. Python Programming: A Modern Approach, Vamsi Kurama, Pearson
2. Python Programming A Modular Approach with Graphics, Database, Mobile, and Web
Applications, Sheetal Taneja, Naveen Kumar, Pearson
3. Programming with Python, A User’s Book, Michael Dawson, Cengage Learning, India Edition
4. Think Python, Allen Downey, Green Tea Press
5. Core Python Programming, W. Chun, Pearson
6. Introduction to Python, Kenneth A. Lambert, Cengage
PROGRAMME OUTCOMES (POs):

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,


and an engineering specialization to the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one‟s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES (PSO's):
A graduate of the Computer Science and Engineering Program will demonstrate:

PSO1: Professional Skills: The ability to understand, analyze and develop computer programs in
the areas related to algorithms ,System Software.

PSO2: Problem-Solving Skills: The ability to apply standard practices and strategies in software
project development to deliver a quality and defect free product .

PSO3: Successful Career and Entrepreneurship: The ability to employ modern computer
languages, techniques in creating innovative career paths to be an entrepreneur, and a zest for
higher studies.
Name of the Programme : [Link] -PPS
CO-PO mapping of the Course
PO1 PO2 PO PO4 PO5 PO6 PO PO PO PO PO PO1 PS PS PS PSO
3 7 8 9 10 11 2 O1 O2 O3 4

Co

To provide an environment of learning in

standards
other
Seme Cou ur

interaction.
learning process and R&D culture.
a state of art teaching

To foster networking with Alumni,


ster rse se

through societal
investigations of complex problems

highand
Na O

of repute
me

for effective
and promote
ut

technologies.
development of solutions

management andfinance
co

Institutes
Modern tool usage

ethical values
m

The engineer and

Life-long learning
Environment and
Problem analysis

Communication
Individual and

commitment.
stakeholders
To nurture
sustainability
Engineering
e

practice
knowledge

team work

emerging

Industry,
N

Conduct
Design/

Project
society

Ethics
o

To
of
1st PPS CO formulate the algorithms for simple problems 1
3 1



1
CO translate given algorithms to a working and correct program
2
1 3 1
CO correct syntax errors as reported by the compilers
3
1 2 2
CO identify and correct logical errors encountered during execution
4
3 2
CO represent and manipulate data with arrays, strings and structures
5
2 1
CO use pointers of different types
6
1 1
Co create, read and write to and from simple text and binary files
7
2 1
Co modularize the code with functions so that they can be reused
8
2 3 1
TEACHING PLAN
DEPARTMENT: A.Y: 2022-2023
BRANCH: PPL R/SEM: I

SUBJECT: PPL FACULTY: Dr. [Link]

Expected Actual Teachin


Book/P Bloom
S. No Topic Date of Date of CO's g
age s
Completi Complet Learnin
No. Taxono
on ion g
my
Process
UNIT - I
1 Week-1 13/4/23 13/4/23 W3csch 1 6 PPT
experiments [Link]

2 Week-1 20/4/23 20/4/23 W3csch 1 6 PPT


experiments [Link]
3 Week-2 27/4/23 27/4/23 W3csch 1 6 PPT
[Link]
4 Week-2 4/5/23 4/5/23 W3csch 1 6 PPT
[Link]

5 Week-3 11/5/23 11/5/23 W3csch 2 6 PPT


[Link]
6 Week-3 1/6/23 W3csch 2 6 PPT
[Link]

7 Week-4 8/6/23 W3csch 3 6


[Link] PPT
8 Week-4 15/6/23 W3csch 3 6 PPT
[Link]
9 Week-5 22/6/23 W3csch 3 6 PPT
[Link]
10 Week-5 22/6/23 W3csch 3 6
[Link]
11 Week-6 29/6/23 W3csch 4 6 PPT
[Link]
12 Week-6 6/7/23 W3csch 4 6 PPT
[Link]
13 Week-7 13/7/23 W3csch 4 6 PPT
[Link]
14 Week-8 20/7/23 W3csch 4 6 PPT
[Link]
15 Week-7 27/7/23 W3csch 4 6 PPT
[Link]

FACULTY HOD PRINCIPAL

TEXT BOOKS:
1. Supercharged Python: Take your code to the next level, Overland
2. Learning Python, Mark Lutz, O'reilly
REFERENCE BOOKS:
1. Python Programming: A Modern Approach, Vamsi Kurama, Pearson
2. Python Programming A Modular Approach with Graphics, Database, Mobile, and Web
Applications, Sheetal Taneja, Naveen Kumar, Pearson
3. Programming with Python, A User’s Book, Michael Dawson, Cengage Learning, India Edition
4. Think Python, Allen Downey, Green Tea Press
5. Core Python Programming, W. Chun, Pearson
6. Introduction to Python, Kenneth A. Lambert, Cengage
MALLAREDDY COLLEGE OF ENGINEERING
Maisammaguda,Dhulapally,Secunderabad
DEPARTMENT OF HUMANITIES & SCIENCES
Name Of The Programme: UG

Name Of The Lab Course Manual:Python Programming

University Code: Q9 Classification Status:Unrestricted/Restricted

Distributed List:Department,Library,Lab-In-Charge
Academic Year: 2022-2023 Updated On:

Semester: IST [Link] II SEM [Link]:


Prepared By:

1)Name:

2)Sign:

3)Designation: Date:
Verified By: * For Iqc Only

1)Name: 1)Name:

2)Sign: 2)Sign:

3)Designation: Date: 3)Designation: Date:


Approved By Hod:

1)Name:

2)Sign: Date:

Faculty Lab Manual:

Name of the class CSE Year: IST YEAR


Semester: II-SEM Section: CSE ALL BRANCHES
Academic year: 2022-2023
Name of the laboratory: PYTHON PROGRAMMING LAB
Prepared by [Link] RANI
Asst/Assoc/Professor

1
Department of Humanities & Sciences
MALLAREDDY COLLEGE OF ENGINEERING
Maisammaguda,Dhulapally,Secunderabad
VISION OF THE INSTITUTE:

To emerge as a center of Excellence for producing professionals who shall be the


leaders
intechnology innovation, entrepreneurship, management and in turn contribute for the
advancement
of society and mankind.

MISSION OF THE INSTITUTE:

 To provide an environment of learning in emerging technologies.

 To nurture state of the art teaching-learning process and R&D culture.

 To foster networking with Alumni, Industry, Institutes of repute and other stake holders
for effective interaction.

 To practice and promote high standards of ethical values through societal commitment.

DEPARTMENT OF HUMANITIES & SCIENCES

Vision
 The department aims to become a pioneer in the field of education and training in
Humanities
and Sciences with enriching value added education.
Mission
 Department strives to transform its students into Confident, Professionally Sound and
Socially
Responsible Engineers who can meet the challenges of advancing technology and work
for the
betterment of mankind.

2
Program Educational Objectives:
1. Graduates shall have the ability to apply knowledge across the disciplines and in emerging
areas of Computer Science & Engineering for higher studies, research, employability and
handle the realistic problems.
2. Graduates shall have good communication skills, possess ethical conduct, sense of
responsibility to serve the society, and protect the environment.
3. Graduates shall have strong foundation in academic excellence, soft skills, managerial
skills, leadership qualities and understand the need for lifelong learning for a successful
professional career.

Program Outcomes:
 PO1:Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems.
 PO2:Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first principles
of mathematics, natural sciences, and engineering sciences
 PO3:Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
 PO4:Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
 PO5:Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
 PO6:The engineer and society: Apply reasoning informed by the contextual knowledge
to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
 PO7:Environment and sustainability: Understand the impact of the professional
3
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
 PO8:Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
 PO9:Individual and team work: Function effectively as an individual, and as a
member or leader in diverse teams, and in multidisciplinary settings.
 PO10:Communication: Communicate effectively on complex engineering activities
with the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
 PO11:Project management and finance: Demonstrate knowledge and understanding of
the engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary environments
 PO12:Life-long learning: Recognize the need for, and have the preparation and ability
to engage in independent and life-long learning in the broadest context of technological
change.
Program Specific Outcome:

 PSO1: Professional skills : the ability to understand ,analyze and develop


computer programs in the areas related to algorithms,system software
 PSO2:Problem solving skills:the ability to apply standard practices and strategies
in software project development to deliver a quality and defect free product.
 PSO3:Successful career and Entrepreneurship: the ability to employ modern
computer languages, techniques, in creating innovative career paths to be an
entrepreneur and a zest for higher studies

4
Course Structure

Course Title PYTHON PROGRAMMING LAB


Course Code
Programme [Link]
Course Structure Practical
L T P Credits
0 0 3 1.5

Course Objectives:
The students will learn the following:
 To work with an IDE to create, edit, compile, run and debug programs
 To analyze the various steps in program development.
 To develop programs to solve basic problems by understanding basic concepts in C like
operators, control statements etc.
 To develop modular, reusable and readable C Programs using the concepts like
functions,
arrays etc.
 To write programs using the Dynamic Memory Allocation concept.
 To create, read from and write to text and binary files
Course Outcomes
The student is expected to learn from this laboratory course the concept of error and its analysis
It also allows the student to develop experimental skills to design new experiments in
Engineering. With the exposure to these experiments the student can compare with the correlate
with experiment.

 CO1. Demonstrate the basic purpose of computer applications in various domains.

 CO2. Write, compile, and debug the programs in C Language.

 CO3. Design the programs involving basic operations, decision structures and looping
structures.

 CO4. Explain the need of writing programs using functions and parameter passing
techniques.

5
 CO5. Demonstrate the array concepts, structure concepts and dynamic memory allocation
with the help of pointers.

 CO6. Use different types of files for reading and writing the data into persistent storage
device and explain the role of simple data structures like stacks, queues

PYTHON PROGRAMMING LAB

PPL – Credits :1.5


CSE,CSE(AIML),CSE(DS),AIDS,IT

Instructions : 3 practicals hrs/week Sessional Marks :40

End Exam : 3 hours End Exam:60

OBJECTIVES:

The course should enable the students to:

 Formulate problems and implement algorithms using C programming language.


 Develop programs using decision structures, loops and functions.
 Learn memory allocation techniques using pointers.
 Use structured programming approach for solving of computing problems in real world.
At the end of this course students will demonstrate the ability to
[Link] DESCRIPTION

1 State to describe the algorithms for problems to be solved.

2 Translate the algorithms/flowcharts into C programs using arrays and functions

3 Develop the programs on files and preprocessor directives.

4 Analyze problems using functions and make use of DMA functions.

5. Evaluate the problems to implement searching and sorting techniques.

Competency Indicators
6
1.1 Demonstrate competence in mathematical 1.1.2 Apply advanced mathematical techniques
model to model and solve Engineering problems
1.4 Demonstrate competence in specialized 1.4.1 Apply advanced programming techniques
engineering knowledge to the program to solve Engineering problems
2.1 Demonstrate an ability to identify and 2.1.2 Identify engineering systems
formulate complex engineering problem. ,variables,and parameters to solve the problems
2.1.3 Identify the mathematical ,engineering
and programming knowledge that applies to
the given problem.
2.3 Demonstarte an ability to formulate and 2.3.1 Combine scientific principles and
integrate a model programming concepts to formulate a process
that is appropriate in terms of applicability and
required accuracy
2.3.2 Identify assumptions which are necessary
to allow formulate a sytem at the level of
accuracy required.
2.4 Demonstrate an ability to execute a 2.4.4. extract desired understanding and
solution process and analyze results conclusions consistent with objectives and
limitations of the analysis.
3.2 Demonstrate an ability to generate a 3.2.2. build models prototypes to develop a
diverse set of alternative design solutions diverse set of design solutions.
3.2.3. Identify suitable criteria for the
evaluation of alternative design solutions.
3.4 Demonstrate an ability to advance an 3.4.1 Refine a conceptual design into a detail
engineering design to defined state. design within the existing constraints (of the
resources).
3.4.2 Generate information through appropriate
test cases to improve or revise the design
4.1 Demonstrate an ability to conduct 4.1.3 Examine relevant models ,tools and
investigations of technical issues consistent techniques of program design ,analysis and
with their level of knowledge and presentation .
understanding 4.1.4 Establish a relationship between desired
date and underlying physical data.
8.1 Demonstrate an ability to recognize ethical 8.1.1 Identify situations of unethical
dilemmas professional conduct and propose ethical
alternatives.
9.1 Demonstrate an ability to form a team and 9.1.1 Recognize a variety of working and
define a role for each member learning preferences appreciate the value of
diversity on a team.
9.1.2 Implement the norms of practice (e.g role
,rules ,charters ,agendas ) for effective team
work to accomplish the goal.

7
SCHEME OF EVALUATION
Total Marks For Each Student to Evaluate In Lab :100 Marks

Out Of 100 Marks :


[Link] Student Continuos Internal Exam Marks: External Exam
Evaluation:15M 25M Marks:75 M
Day To Day Evaluation :15M
Student Performance During Every Day To Day Evaluation:
Lab Session 15M Program Analysis
1 Knowledge Gained:1M Program Analysis Design
Execution:2M Design Algorithm 30M
Result&Conclusion:2M Algorithm 3M Flowchart
VIVA VOCE:2M
(Communication,LifeLonglearning) Flowchart Source Code
Record : 5M Source Code Execution : 20M
Program Analysis Execution : 3M Result: 15M
2 Design
Algorithm Result: 2M Viva Voce: 10M
Flowchart
Viva Voce: 2M
Source Code
3 Attendance:3M
Depends on percentage of lab
attendance 65%-100%
1. >75% = 2M
2. >75% && <66%= 1M
3. <65%=0M

RUBRICS
Key 4-very good 3-good 2-fair 1- Need to
performance improve
Criteria(kpc)
(25pts)
Problem The thorough The better The basic The partial
statement(2) knowledge of knowledge of knowledge of knowledge of
problem problem problem problem statement(3)
statement(3) statement(2) statement(2)
Experimental The The The experimental The experimental
procedure experimental experimental procedure is procedure is
(Algorithm/Fl procedure is procedure is explained clearly explained some minor
owchart/tools explained with explained and the few implementation
Description the relevant clearly and details are details are missing

8
and implementation the details are covered with with Simulation(2)
Simulation(5) of Tool covered with Simulation(3)
Simulation(5) Simulation(4)
Test Cases Produces correct Produces Produces correct Produces wrong
Verificaton(3) output for all correct output output forfew output for most of the
mentioned test for majority important test cases in
cases correctly in of test cases possible test implementation/simul
implementation/s corre ctly in cases correctly in ation(1)
imulation(3) implementatio implementation/si
n/simulation(3 mulation(3)
)
Oral In depth Good Basic knowledge With basic
Presentation/ knowledge on knowledge on on the concept knowledge on the
Viva(5) the concept and the concept and answered few concept and answered
answered all the and answered of the few of the
questions(4) all the questions(2) questions(2)
questions(4)
Presentation/d Presented Presented Presented submitted
ocumentation accurately all the accurately all documents in a documents in
based on prescribed the required readable manner ambiguity and not on
record/code of documentation documentatio but not so neatly time with least code
conduct(10) on time with n on time as .s ubmitted of conduct(7)
good code of per the documentation on
conduct(10) prescribed time with
format good reminders trying
code of to adopt good
conduct(9) code of
conduct(8)

9
LIST OF EQUIPMENTS IN
PROGRAMMING FOR PROBLEM
SOLUTION LABORATORY

[Link] Name Of The Make Quantity Software Place


Equipment

Dell
Desktop
1 Intel I3@[Link],8gb, 64 PPL LAB-1
Systems
Keyboard,Mouse

Lennovo
Desktop Pentium
2 64 PPL LAB-2
Systems @3.20ghz,2gb
Keyboard,Mouse

INSTRUCTIONS FOR STUDENT WHILE ENTERING IN LAB

These are the instructions for the students attending the lab:

 Before entering the lab the student should carry the following things (MANDATORY)
1. Identity card issued by the college.
2. Class notes
3. Lab observation book
4. Lab Manual
5. Lab Record
 Student must sign in and sign out in the register provided when attending
the lab session without fail.
 Come to the laboratory in time. Students, who are late more than 15 min.,
will not be allowed to attend the lab.
 Students need to maintain 100% attendance in lab if not a strict action will be taken.
 All students must follow a Dress Code while in the laboratory
 Foods, drinks are NOT allowed.
 All bags must be left at the indicated place.

10
 Refer to the lab staff if you need any help in using the lab.
 Respect the laboratory and its other users.
 Workspace must be kept clean and tidy after experiment is completed.
 Read the Manual carefully before coming to the laboratory and be sure about
what you are supposed to do.
 Do the experiments as per the instructions given in the manual.
 Copy all the programs to observation which are taught in class before
attending the lab session.
 Students are not permitted to use phones, Flash drives, Internet without
permission of lab-in charge.
 
Lab records need to be submitted on or before the date of submission.
















PYTHON PROGRAMMING LABORATORY

[Link]. I Year II Sem. L T P


C
0 1 2 2
Course Objectives:
 To install and run the Python interpreter

11
 To learn control structures.
 To Understand Lists, Dictionaries in python
 To Handle Strings and Files in Python
Course Outcomes: After completion of the course, the student should be able to
● Develop the application specific codes using python.
● Understand Strings, Lists, Tuples and Dictionaries in Python
● Verify programs using modular approach, file I/O, Python standard library
● Implement Digital Systems using Python
Note: The lab experiments will be like the following experiment examples

Week -1:
1. i) Use a web browser to go to the Python website [Link] This page contains information
about Python and links to Python-related pages, and it gives you the ability to search the Python
documentation.
ii) Start the Python interpreter and type help() to start the online help utility.
2. Start a Python interpreter and use it as a
Calculator.3.
i) Write a program to calculate compound interest when principal, rate and number of periods are
given.
ii) Given coordinates (x1, y1), (x2, y2) find the distance between two points
4. Read name, address, email and phone number of a person through keyboard and print the
details.

Week - 2:
1. Print the below triangle using for
loop.5
44
333
2222
11111
2. Write a program to check whether the given input is digit or lowercase character or uppercase
character or a special character (use 'if-else-if' ladder)
3. Python Program to Print the Fibonacci sequence using while loop
4. Python program to print all prime numbers in a given interval (use break)

Week - 3:
1. i) Write a program to convert a list and tuple into arrays.
ii) Write a program to find common values between two arrays.
2. Write a function called gcd that takes parameters a and b and returns their greatest common divisor.
3. Write a function called palindrome that takes a string argument and returnsTrue if it is a palindrome
and False otherwise. Remember that you can use the built-in function len to check the length of a string.

12
Week - 4:
1. Write a function called is_sorted that takes a list as a parameter and returns True if the list is sortedin
ascending order and False otherwise.
2. Write a function called has_duplicates that takes a list and returns True if there is any element that
appears more than once. It should not modify the original list.
i). Write a function called remove_duplicates that takes a list and returns a new list with only the
unique elements from the original. Hint: they don’t have to be in the same order.
ii). The wordlist I provided, [Link], doesn’t contain single letter words. So you might want to
add“I”, “a”, and the empty string.
iii). Write a python code to read dictionary values from the user. Construct a function to invert its
content. i.e., keys should be values and values should be keys.
3. i) Add a comma between the characters. If the given word is 'Apple', it should become 'A,p,p,l,e'
ii) Remove the given word in all the places in a string?
iii) Write a function that takes a sentence as an input parameter and replaces the first letter of every
word with the corresponding upper case letter and the rest of the letters in the word by
corresponding letters in lower case without using a built-in function?
4. Writes a recursive function that generates all binary strings of n-bit length

Week - 5:
1. i) Write a python program that defines a matrix and prints
ii) Write a python program to perform addition of two square matrices
iii) Write a python program to perform multiplication of two square matrices
2. How do you make a module? Give an example of construction of a module using different geometrical
shapes and operations on them as its functions.
3. Use the structure of exception handling all general purpose exceptions.
Week-6:
1. a. Write a function called draw_rectangle that takes a Canvas and a Rectangle as arguments and
draws a representation of the Rectangle on the Canvas.
b. Add an attribute named color to your Rectangle objects and modify draw_rectangle so that it
uses the color attribute as the fill color.
c. Write a function called draw_point that takes a Canvas and a Point as arguments and draws a
representation of the Point on the Canvas.
d. Define a new class called Circle with appropriate attributes and instantiate a few Circle objects.
Write a function called draw_circle that draws circles on the canvas.
2. Write a Python program to demonstrate the usage of Method Resolution Order (MRO) in multiple
levels of Inheritances.
3. Write a python code to read a phone number and email-id from the user and validate it for
correctness.
Week- 7
1. Write a Python code to merge two given file contents into a third file.
2. Write a Python code to open a given file and construct a function to check for given words present init
and display on found.
3. Write a Python code to Read text from a text file, find the word with most number of occurrences
4. Write a function that reads a file file1 and displays the number of words, number of vowels, blank
spaces, lower case letters and uppercase letters.

13
Week - 8:
1. Import numpy, Plotpy and Scipy and explore their functionalities.
2. a) Install NumPy package with pip and explore it.
3. Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
4. Write a program to implement Half Adder, Full Adder, and Parallel Adder
5. Write a GUI program to create a window wizard having two text labels, two text fields and two buttons
as Submit and Reset.
INTERNAL (DAY TO DAY) EVALUATION METHODOLOGY:

Program Analysis,

(Communication,Lif
Algorithm,Flowchar

Result&Conclusion
KnowledgeGained

eLonglearning)
VIVA VOCE
t,program
ExperimentName

Execution
[Link]

Design

TOTAL
2 4 2 2 5 15

Week -1:
1.i) Use a web browser to go to the
Python website [Link] This
page contains information about
Python and links to Python-related
pages, and it gives you the ability to
search the Python documentation.
[Link]) Start the Python interpreter and type help()
1
to start the online help utility.
[Link] a Python interpreter and use it as a
Calculator.3.
[Link] a program to calculate compound
interest when principal, rate and number of
periods aregiven.
Given coordinates (x1, y1), (x2, y2) find the
distance between two points
Read name, address, email and phone number of
a person through keyboard and print the details.

Week - 2:
Print the below triangle using for loop. 5
44
2 333
2222
11111
Write a program to check whether the
given input is digit or lowercase character

14
or uppercasecharacter or a special character
(use 'if-else-if' ladder)
Python Program to Print the Fibonacci
sequence using while loop
Python program to print all prime numbers
in a given interval (use break)

Week-3:
i) Write a program to convert a list and tuple
into arrays.
ii) Write a program to find common values
between two arrays.
Write a function called gcd that takes
3 parameters a and b and returns their greatest
common divisor.
Write a function called palindrome that
takes a string argument and returnsTrue if it
is a palindromeand False otherwise.
Remember that you can use the built-in
function len to check the length of a string.
Week - 4:
Write a function called is_sorted that takes a list
as a parameter and returns True if the list is
sortedin ascending order and False otherwise.
Write a function called has_duplicates that takes
a list and returns True if there is any element
thatappears more than once. It should not modify
the original list. Write a function called
remove_duplicates that takes a list and
returns a new list with only theunique
elements from the original. Hint: they don’t
have to be in the same order.
The wordlist I provided, [Link], doesn’t
contain single letter words. So you might
want to add“I”, “a”, and the empty string.
4 Write a python code to read dictionary
values from the user. Construct a function
to invert itscontent. i.e., keys should be
values and values should be keys.
i) Add a comma between the characters. If
the given word is 'Apple', it should become
'A,p,p,l,e'
Remove the given word in all the places in a
string?
Write a function that takes a sentence as an
input parameter and replaces the first letter
of everyword with the corresponding upper
case letter and the rest of the letters in the
word by corresponding letters in lower case
without using a built-in function?
Writes a recursive function that generates all

15
binary strings of n-bit length

Week - 5:
i) Write a python program that defines a matrix
and prints
Write a python program to perform addition of
two square matrices
Write a python program to perform
5 multiplication of two square matrices
How do you make a module? Give an example of
construction of a module using different
geometricalshapes and operations on them as its
functions.
Use the structure of exception handling all
general purpose exceptions.
Week-6:
a. Write a function called draw_rectangle that
takes a Canvas and a Rectangle as arguments
anddraws a representation of the Rectangle on
the Canvas.
Add an attribute named color to your Rectangle
objects and modify draw_rectangle so that it
uses the color attribute as the fill color.
Write a function called draw_point that takes a
Canvas and a Point as arguments and draws a
representation of the Point on the Canvas.
6
Define a new class called Circle with appropriate
attributes and instantiate a few Circle objects.
Write a function called draw_circle that draws
circles on the canvas.
Write a Python program to demonstrate the
usage of Method Resolution Order (MRO) in
multiplelevels of Inheritances.
Write a python code to read a phone number
and email-id from the user and validate it for
correctness.

Week- 7
Write a Python code to merge two given file
contents into a third file.
Write a Python code to open a given file and
construct a function to check for given words
present init and display on found.
7 Write a Python code to Read text from a text file,
find the word with most number of occurrences
Write a function that reads a file file1 and
displays the number of words, number of
vowels, blankspaces, lower case letters and
uppercase letters.

Week - 8:
8 [Link] numpy, Plotpy and Scipy and
explore their functionalities.

16
2.a) Install NumPy package with pip and
explore it.
[Link] a program to implement Digital
Logic Gates – AND, OR, NOT, EX-OR
[Link] a program to implement Half
Adder, Full Adder, and Parallel Adder
[Link] a GUI program to create a
window wizard having two text
labels, two text fields and two
buttonsas Submit and Reset.

AVERAGE /TOTAL INTERNAL MARKS

INDEX

[Link] PROGRAM PAGE NO

17
Week -1:
i) Use a web browser to go to the Python website [Link] This page contains
information about Python and links to Python-related pages, and it gives you the ability to
search the Python documentation.
ii) Start the Python interpreter and type help() to start the online help utility.
1 Start a Python interpreter and use
it as a Calculator.3.
iii) Write a program to calculate compound interest when principal, rate and number of
periods aregiven.
iv) Given coordinates (x1, y1), (x2, y2) find the distance between two points
Read name, address, email and phone number of a person through keyboard and print the details.

Week - 2:
Print the below
triangle using for
loop.5
44
333
2
2222
11111
Write a program to check whether the given input is digit or lowercase character or
uppercasecharacter or a special character (use 'if-else-if' ladder)
Python Program to Print the Fibonacci sequence using while loop
Python program to print all prime numbers in a given interval (use break)

Week - 3:
i) Write a program to convert a list and tuple into arrays.
3 ii) Write a program to find common values between two arrays.
Write a function called gcd that takes parameters a and b and returns their greatest common divisor.
Write a function called palindrome that takes a string argument and returnsTrue if it is a palindromeand
False otherwise. Remember that you can use the built-in function len to check the length of a string
Week - 4:
Write a function called is_sorted that takes a list as a parameter and returns True if the list is sortedin
ascending order and False otherwise.
Write a function called has_duplicates that takes a list and returns True if there is any element that
appears more than once. It should not modify the original list.
Write a function called remove_duplicates that takes a list and returns a new list with only theunique
elements from the original. Hint: they don’t have to be in the same order.
The wordlist I provided, [Link], doesn’t contain single letter words. So you might want to add“I”, “a”,
and the empty string.
4 Write a python code to read dictionary values from the user. Construct a function to invert itscontent.
i.e., keys should be values and values should be keys.
i) Add a comma between the characters. If the given word is 'Apple', it should become 'A,p,p,l,e'
Remove the given word in all the places in a string?
Write a function that takes a sentence as an input parameter and replaces the first letter of everyword with
the corresponding upper case letter and the rest of the letters in the word by corresponding letters in lower
case without using a built-in function?
Writes a recursive function that generates all binary strings of n-bit length

18
Week - 5:
i) Write a python program that defines a matrix and prints
Write a python program to perform addition of two square matrices
Write a python program to perform multiplication of two square matrices
5 How do you make a module? Give an example of construction of a module using different geometrical
shapes and operations on them as its functions.
Use the structure of exception handling all general purpose exceptions.

Week-6:
a. Write a function called draw_rectangle that takes a Canvas and a Rectangle as arguments anddraws a
representation of the Rectangle on the Canvas.
Add an attribute named color to your Rectangle objects and modify draw_rectangle so that ituses the
color attribute as the fill color.
Write a function called draw_point that takes a Canvas and a Point as arguments and draws a
6 representation of the Point on the Canvas.
Define a new class called Circle with appropriate attributes and instantiate a few Circle [Link] a
function called draw_circle that draws circles on the canvas.
Write a Python program to demonstrate the usage of Method Resolution Order (MRO) in multiplelevels
of Inheritances.
Write a python code to read a phone number and email-id from the user and validate it for
correctness
Week- 7
Write a Python code to merge two given file contents into a third file.
Write a Python code to open a given file and construct a function to check for given words present init and
display on found.
7 Write a Python code to Read text from a text file, find the word with most number of occurrences
Write a function that reads a file file1 and displays the number of words, number of vowels, blank
spaces, lower case letters and uppercase letters.

Week - 8:
Import numpy, Plotpy and Scipy and explore their functionalities.
a) Install NumPy package with pip and explore it.
Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
8 Write a program to implement Half Adder, Full Adder, and Parallel Adder
Write a GUI program to create a window wizard having two text labels, two text fields and two buttonsas
Submit and Reset.

19
INTRODUCTION TO COMPUTERS

What are Computer Programming Languages?


Computer programming languages allow us to give instructions to a computer in a
language the computer understands. Just as many human-based languages exist,
there are an array of computer programming languages that programmers can use to
communicate with a computer. The portion of the language that a computer can
understand is called a “binary.” Translating programming language into binary is
known as “compiling.” Each language, from C Language to Python, has its own
distinct features, though many times there are commonalities between programming
languages.

PYTHON PROGRAMMING LAB MANUAL


[Link]: Write a program to calculate compound interest when principal, rate
and number of periods are given.

Program:

def compound_interest(principal, rate, time):

# Calculates compound interest

Amount = principal * (pow((1 + rate / 100), time))

CI = Amount - principal

print("Compound interest is", CI)

# Driver Code

#Taking input from user.

principal = int(input("Enter the principal amount: "))

rate = int(input("Enter rate of interest: "))

time = int(input("Enter time in years: " ))

20
#Function Call

compound_interest(principal,rate,time)

Input:
Enter the principal amount: 3000
Enter rate of interest: 5
Enter time in years: 3
Output:
Compound interest is 472.875

21
[Link]: Given coordinates (x1, y1), (x2, y2) find the distance between two
points.
Program:
x1=int(input("enter x1 : "))

x2=int(input("enter x2 : "))

y1=int(input("enter y1 : "))

y2=int(input("enter y2 : "))

result= ((((x2 - x1 )**2) + ((y2-y1)**2) )**0.5)

print("distance between",(x1,x2),"and",(y1,y2),"is : ",result)

Output :
enter x1 : 4

enter x2 : 6

enter y1 : 0

enter y2 : 6

distance between (4, 6) and (0, 6) is : 6.324555320336759

22
[Link]: Read name, address, email and phone number of a person through
keyboard and print the details.

Program:

def personal_details():
name, age = "Simon", 19
address = "Bangalore, Karnataka, India"
print("Name: {}\nAge: {}\nAddress: {}".format(name, age, address))

personal_details()

OUTPUT:

Name: Simon
Age: 19
Address: Bangalore, Karnataka, India

23
4. Aim: Print the below triangle using for loop.

Program:

rows = 6
# if you want user to enter a number, uncomment the below line
# rows = int(input('Enter the number of rows'))
# outer loop
for i in range(rows):
# nested loop
for j in range(i):
# display number
print(i, end=' ')
# new line after each row
print('')

OUTPUT:

22

333

4444

55555

[Link]: Write a program to check whether the given input is digit or lowercase

24
character or uppercase character or a special character (use 'if-else-if' ladder).

Program:
ch = input("Please Enter Your Own Character : ")

if(ch >= 'A' and ch <= 'Z'):

print("The Given Character ", ch, "is an Uppercase Alphabet")

elif(ch >= 'a' and ch <= 'z'):

print("The Given Character ", ch, "is a Lowercase Alphabet")

else:

print("The Given Character ", ch, "is Not a Lower or Uppercase Alphabet")

OUTPUT:

Please Enter Your Own Character : o

The Given Character o is a Lowercase Alphabet

>>>

Please Enter Your Own Character : R

The Given Character R is an Uppercase Alphabet

>>>

Please Enter Your Own Character : $

The Given Character $ is Not a Lower or Uppercase Alphabet

25
[Link]: Python Program to Print the Fibonacci sequence using while loop.

Program:
Number = int(input("\nPlease Enter the Range : "))
# Initializing First and Second Values
i=0
First_Value = 0
Second_Value = 1
# Find & Displaying
while(i < Number):
if(i <= 1):
Next = i
else:
Next = First_Value + Second_Value
First_Value = Second_Value
Second_Value = Next
print(Next)
i=i+1

OUTPUT:

Please Enter the Range : 4

26
7. Aim: Python program to print all prime numbers in a given interval (use
break).

Program:

def primenumber(MyNum):
n=0
i=2
for i in range(2,MyNum//2+1):
if MyNum % i == 0:
n=n+1
break
if n == 0:
print(MyNum, end=" ")

x = 50
print("Prime numbers less than", x, "are:")
for i in range(2, x+1):
primenumber(i)
OUTPUT:

Prime numbers less than 50 are:


2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

27
[Link]:
i) Write a program to convert a list and tuple into arrays.

Program:
def convert(list):
return tuple(i for i in list)
# Driver function
list = [1, 2, 3, 4]
print(convert(list))

OUTPUT:
(1, 2, 3, 4)

28
Aim:
ii) Write a program to find common values between two arrays.
Program:

array1 = [1, 2, 3, 4, 5]
array2 = [4, 5, 6, 7, 8]

common_values = set(array1) & set(array2)

print("The common values between the two arrays are:", list(common_values))

OUTPUT:
The common values between the two arrays are: [4, 5]

29
[Link]: Write a function called gcd that takes parameters a and b and returns
their greatest common divisor.
Program:

def GCD_Loop( a, b):


if a > b: # define the if condition
temp = b
else:
temp = a
for i in range(1, temp + 1):
if (( a % i == 0) and (b % i == 0 )):
gcd = i
return gcd
x = int(input (" Enter the first number: ") ) # take first no.
y =int (input (" Enter the second number: ")) # take second no.
num = GCD_Loop(x, y) # call the gcd_fun() to find the result
print("GCD of two number is: ")
print(num) # call num

Output:

30
10. Aim: Write a function called palindrome that takes a string argument and
returnsTrue if it is a palindrome and False otherwise. Remember that you can
use the built-in function len to check the length of a string.
Program:

#Enter input string


string = input("Enter string : ")

#Declare an empty string variable


revstr = ""

#Iterate string with for loop


for i in string:
revstr = i + revstr
print("Reversed string : ", revstr)

if(string == revstr):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")

OUTPUT:

31
11. Aim: Write a function called is_sorted that takes a list as a parameter and
returns True if the list is sorted in ascending order and False otherwise.

Program:

test_list = [1, 4, 5, 8, 10]

# printing original list


print ("Original list : " + str(test_list))

# using naive method to


# check sorted list
flag = 0
i=1
while i < len(test_list):
if(test_list[i] < test_list[i - 1]):
flag = 1
i += 1

# printing result
if (not flag) :
print ("Yes, List is sorted.")
else :
print ("No, List is not sorted.")

Output :
Original list : [1, 4, 5, 8, 10]
Yes, List is sorted.

32
[Link]: Write a function called has_duplicates that takes a list and returns
True if there is any element that appears more than once. It should not modify
the original list.

i). Write a function called remove_duplicates that takes a list and returns a new
list with only the bunique elements from the original. Hint: they don’t have to
be in the same order.

Program:

def Remove(duplicate):
final_list = []
for num in duplicate:
if num not in final_list:
final_list.append(num)
return final_list

# Driver Code
duplicate = [2, 4, 10, 20, 5, 2, 20, 4]
print(Remove(duplicate))

Output:
[2, 4, 10, 20, 5]

33
ii).
Aim: Write a python code to read dictionary values from the user. Construct a
function to invert its content. i.e., keys should be values and values should be
keys.
Program:
def invert_dict(d):
inverse = {}
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse

# Ask user to input dictionary


d = {}
while True:
key = input("Enter key (or 'q' to stop): ")
if key == 'q':
break
val = input("Enter value: ")
d[key] = val

# Print original dictionary


print("Original dictionary:")
print(d)

# Invert dictionary using function and print result


print("Inverted dictionary:")
inverse = invert_dict(d)
print(inverse)

OUTPUT:
Enter key (or 'q' to stop): 22
Enter value: "ram"
Enter key (or 'q' to stop): 34
Enter value: "sita"
Enter key (or 'q' to stop): 54
Enter value: "mahesh"
Enter key (or 'q' to stop): q
Original dictionary:
{'22': '"ram"', '34': '"sita"', '54': '"mahesh"'}
Inverted dictionary:
{'"ram"': ['22'], '"sita"': ['34'], '"mahesh"': ['54']}

34
13.
Aim:
i) Add a comma between the characters. If the given word is 'Apple', it should
become 'A,p,p,l,e'
Program:

def add_comma(word):
comma_word = ','.join(word)
return comma_word

# calling function
add_comma("apple")

OUTPUT:

a,p,p,l,e

35
Aim:
ii) Remove the given word in all the places in a string?

Program:

def remove_word(word, text):


"""
Removes all occurrences of a word in a given string.
"""
return [Link](word, '')

text = "This is a test string. This is only a test."


word = "test"
new_text = remove_word(word, text)
print(new_text)

OUTPUT:
This is a string. This is only a .

36
Aim:
iii) Write a function that takes a sentence as an input parameter and replaces
the first letter of every word with the corresponding upper case letter and the
rest of the letters in the word by corresponding letters in lower case without
using a built-in function?

Program:

def title_case(sentence):
# Split the sentence into words
words = [Link]()

# Iterate over the words and apply the title case transformation
for i in range(len(words)):
word = words[i]
# Extract the first letter and convert it to upper case
first_letter = word[0].upper()
# Extract the rest of the letters and convert them to lower case
rest_letters = word[1:].lower()
# Concatenate the first letter and the rest of the letters
words[i] = first_letter + rest_letters

# Join the words back into a sentence and return it


return ' '.join(words)

# calling a function
sentence = "I am learning python in Malla Reddy College of Engineering for wo
men"
title_case(sentence)

OUTPUT:
I Am Learning Python In Malla Reddy College Of Engineering For Women

37
14.
Aim: Writes a recursive function that generates all binary strings of n-bit
length.

Program:

def printTheArray(arr, n):

for i in range(0, n):


print(arr[i], end = " ")

print()

OUTPUT:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

38
15.
Aim:
i) Write a python program that defines a matrix and prints.

Program:

R = int(input("Enter the number of rows:"))


C = int(input("Enter the number of columns:"))
# Initialize matrix
matrix = []
print("Enter the entries rowwise:")

# For user input


for i in range(R): # A for loop for row entries
a =[]
for j in range(C): # A for loop for column entries
[Link](int(input()))
[Link](a)

# For printing the matrix


for i in range(R):
for j in range(C):
print(matrix[i][j], end = " ")
print()

Output:
Enter the number of rows:2
Enter the number of columns:3
Enter the entries rowwise:
1
2
3
4
5
6

123
456

39
Aim:
ii) Write a python program to perform addition of two square matrices.
Program:

X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]

Y = [[9,8,7],
[6,5,4],
[3,2,1]]

result = [[X[i][j] + Y[i][j] for j in range


(len(X[0]))] for i in range(len(X))]

for r in result:
print(r)

Output
[10, 10, 10]
[10, 10, 10]
[10, 10, 10]

40
Aim:
iii) Write a python program to perform multiplication of two square
matrices.
Program:

# take a 3x3 matrix


A = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]

# take a 3x4 matrix


B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]

result = [[0, 0, 0, 0],


[0, 0, 0, 0],
[0, 0, 0, 0]]

# iterating by row of A
for i in range(len(A)):

# iterating by column by B
for j in range(len(B[0])):

# iterating by rows of B
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

for r in result:
print(r)
Output:
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]

41
16.
Aim: How do you make a module? Give an example of construction of a
module using different geometrical shapes and operations on them as its
functions.
Program:

import shapes
print(shapes.circle_area(5))
print(shapes.square_perimeter(5)

OUTPUT:
78.53981633974483
20

42
17.
Aim: Use the structure of exception handling all general purpose exceptions.

Program:

a = [1, 2, 3]
try:
print ("Second element = %d" %(a[1]))

# Throws error since there are only 3 elements in array


print ("Fourth element = %d" %(a[3]))

except:
print ("An error occurred")

OUTPUT:
Second element = 2
An error occurred

43
18.
Aim: a. Write a function called draw_rectangle that takes a Canvas and a
Rectangle as arguments and draws a representation of the Rectangle on the
Canvas.

Program:

1 import tkinter as tk
2
3 master = [Link]()
4
5
6 def rectangle(event):
7 w.create_rectangle(event.x, event.y, event.x + 10, event.y + 10, fill="blue")
8
9
10 w = [Link](master, width=200, height=200)
11 [Link]()
12
13 [Link]("&lt;Button-1&gt;", rectangle)
14
15 [Link]()

OUTPUT

44
19 .
Aim: Write a Python program to demonstrate the usage of Method Resolution
Order (MRO) in multiple levels of Inheritances.

Program:

class A:
def rk(self):
print(" In class A")
class B(A):
def rk(self):
print(" In class B")

r = B()
[Link]()

Output:

In class B

45
20.
Aim: Write a Python code to merge two given file contents into a third
file.

Program:
data = data2 = ""

# Reading data from file1


with open('[Link]') as fp:
data = [Link]()

# Reading data from file2


with open('[Link]') as fp:
data2 = [Link]()

# Merging 2 files
# To add the data of file2
# from next line
data += "\n"
data += data2

with open ('[Link]', 'w') as fp:


[Link](data)

OUTPUT:

46
21.
Aim: Write a Python code to open a given file and construct a function to check
for given words present in it and display on found.

Program:

with open('[Link]','r') as file:

# reading each line


for line in file:

# reading each word


for word in [Link]():

# displaying the words


print(word)

OUTPUT:

47
22.
Aim: Write a Python code to Read text from a text file, find the word with most
number of occurrences.

Program:

word = "apple"
count = 0
with open("[Link]", 'r') as f:
for line in f:
words = [Link]()
for i in words:
if(i==word):
count=count+1
print("Occurrences of the word", word, ":", count)

Output:

Occurrences of the word apple: 2

48
23.
Aim: Write a function that reads a file file1 and displays the number of words,
number of vowels, blank spaces, lower case letters and uppercase letters.

Program:

def counting(filename):

# Opening the file in read mode

txt_file = open(filename, "r")

# Initialize three variables to count number of vowels,

# lines and characters respectively

vowel = 0

line = 0

character = 0

# Make a vowels list so that we can

# check whether the character is vowel or not

vowels_list = ['a', 'e', 'i', 'o', 'u',

'A', 'E', 'I', 'O', 'U']

# Iterate over the characters present in file

for alpha in txt_file.read():

49
# Checking if the current character is vowel or not

if alpha in vowels_list:

vowel += 1

# Checking if the current character is

# not vowel or new line character

elif alpha not in vowels_list and alpha != "\n":

character += 1

# Checking if the current character

# is new line character or not

elif alpha == "\n":

line += 1

# Print the desired output on the console.

print("Number of vowels in ", filename, " = ", vowel)

print("New Lines in ", filename, " = ", line)

print("Number of characters in ", filename, " = ", character)

# Calling the function counting which gives the desired output

counting('[Link]')

Output:

Number of vowels in [Link] = 23

50
New Lines in [Link] = 2
Number of characters in [Link] = 54

51
24.
Aim: Import numpy, Plotpy and Scipy and explore their functionalities.

Program:

import numpy as np
import [Link] as plt
import scipy as sp

# Create a one-dimensional array


a = [Link]([1, 2, 3, 4, 5])

# Create a two-dimensional array


b = [Link]([[1, 2, 3], [4, 5, 6]])

# Perform basic arithmetic operations on arrays


c=a+2
d=b*3

# Use NumPy functions to perform mathematical operations on arrays


e = [Link](a)
f = [Link](b)

# Reshape an array
g = [Link](b, (3, 2))

# Transpose an array
h = [Link](b)

# matplot
# Create a simple line plot
x = [Link](0, 10, 100)
y = [Link](x)
[Link](x, y)
[Link]()

# Create a scatter plot


x = [Link](100)
y = [Link](100)
[Link](x, y)
[Link]()

# Create a histogram
data = [Link](1000)
[Link](data, bins=30)

52
[Link]()

# Scipy

# Perform a linear regression


x = [Link]([1, 2, 3, 4, 5])
y = [Link]([2, 4, 5, 4, 5])
slope, intercept, r_value, p_value, std_err = [Link](x, y)

# Find the roots of a function


def f(x):
return x**3 - 3*x**2 + 1
root = [Link].root_scalar(f, method='brentq', bracket=[-10, 10])

# Perform Fourier transforms


data = [Link](1000)
fft = [Link](data)

53
25.
Aim: Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-
OR

Program:

def AND_gate(a, b):


if a == 1 and b == 1:
return 1
else:
return 0

# OR gate implementation
def OR_gate(a, b):
if a == 1 or b == 1:
return 1
else:
return 0

# NOT gate implementation


def NOT_gate(a):
if a == 0:
return 1
else:
return 0

# XOR gate implementation


def XOR_gate(a, b):
if a != b:
return 1
else:
return 0

54
26.
Aim: Write a program to implement Half Adder, Full Adder, and Parallel Adder

Program:

def half_adder(a, b):


"""
Computes the sum and carry of two bits using a half adder.
"""
sum = a ^ b
carry = a & b
return sum, carry

print(half_adder(9,10))

# Full Adder program

def full_adder(a, b, c):


"""
Computes the sum and carry of three bits using a full adder.
"""
sum = a ^ b ^ c
carry = (a & b) | (b & c) | (c & a)
return sum, carry

print(full_adder(10,5,14))

# Parallel Adder

def parallel_adder(a, b):


"""
Computes the sum of two n-bit binary numbers using a parallel adder.
"""
n = len(a)
carry = 0
result = ""
for i in range(n-1, -1, -1):
sum, carry = full_adder(int(a[i]), int(b[i]), carry)
result = str(sum) + result
if carry:
result = str(carry) + result
return result

# calling function
a = "1010"

55
b = "1101"

print(parallel_adder(a, b)) # Output: 10111

OUTPUT:
(3, 8)
(1, 14)
10111

56

You might also like