Professional Documents
Culture Documents
Look forward,
learn modern
knowledge, and
do not waste
time in studies
of old subjects of
no values.
Lab Manual
B.Sc. (CA)
SEMESTER - II
Editor:
Dr. Aasim Zafar
COURSE DESCRIPTION
This manual is intended for the Second year students in the
subject of Programming with Python. This manual typically contains
practical/Lab Sessions related to Programming with Python covering
various aspects in order to enhance subject understanding.
There are two ways to use the Python interpreter: shell mode and
script mode. In shell mode, you type Python statements into the Python
shell and the interpreter immediately prints the result. In script mode,
you type statements into the editor and save it in a file known as script.
The interpreter executes the code of the script.
AMU
AMU
CSD
CONTENT
This course is designed to provide the students the opportunity of
learning both – concepts of C, implementing algorithms of data
structures and programming with Python. This course is indented to
develop a deep understanding of various operations on data structure
such as searching, sorting, insertion, deletion and traversing and
provides students the idea of new programming language. Apart from
basic concepts, it helps to understand the concept of lists, tuples,
dictionaries and file handling.
OBJECTIVES
This course is designed to help students in:
CSD
OUTCOMES
After completing this course, the students would be able to:
CSD
CSD
SIGNATURE
PAGE NO.
OF THE
PROBLEMS WITH DESCRIPTION TEACHER
WITH DATE
1#
1 2#
3#
1#
2 2#
3#
1#
3 2#
3#
1#
4 2#
3#
Note: The students should use Header and Footer mentioning their roll no. & name in footer and page no in header.
WEEK #1
To understand concept of control construct, arrays,
PEDMAS Law.
Note: When naming a Python program, a .py extension must be used. Failing
to do so will result in code that will not be recognized by the system as a Python
program.
PROBLEMS
S
1# Scenario: A courier company has number of items to be delivered to its
intended customers through its salesman. The salesman visits following cities
to deliver the respective items:
1. Aligarh 18
2. Agra 25
3. Baroda 13
4. Banaras 43
5. Chennai 8
6. New Delhi 67
7. New Jalpaiguri 29
8. Howrah 11
9. Kolkata 56
10. Mumbai 33
CSD
Python.
To learn the rules to define variables in Python.
To learn the use of Assignment (=) and comparison (==)
operators in Python.
To learn the special use of + for string concatenation in
Python.
To learn the basic input receiving command is raw_input
in Python.
Note: To Learn three basic types of simple variables in Python: integers (whole
numbers, commonly used as an index), floats (that is, numbers with a decimal
point, AKA real numbers), and strings (collections of alphanumeric characters
such as names, sentences, or numbers that are not manipulated
mathematically such as a part number or zip code).
The first assignment to a variable creates it. The variable types don’t need to be
declared. Python figures out the variable types on its own.
AMU
AMU
CSD
b) Write a program to display name of the cities along with their length, and
identity cities composed of two words.
c) The number of items of „Agra‟ and „Kolkata‟ are accidently interchanged.
Correct them by writing a swap function using pointers.
CSD
PROBLEMS
S
1# Scenario: A university has different entities such as Department, Programs
and Student whose data members and member functions are given below:
Teacher- { Data Members: Name, department, hours, programsTaught;
Member Function: setDetails(), getDetails()}
Program- {Data Members: Name, department, duration;
Member Functions: setDetails(), getDetails()}
Student- {Data Members: Name, RollNo, Program, Department}
Member Function: setDetails(), getDetails()}
AMU
AMU
CSD
2# Write a Python program which accepts the inputs from the user and do
the following using functions.
a) To find largest of 3 numbers.(Function)
b) To generate first 4th Fibonacci term.(function)
c) To compute factorial of an integer n recursively.(function)
d) To find volume of cylinder or cube or rectangular box.
e) To find area of rectangle.
f) To find circumference of circle.(Using constructor)
g) To exchange the values of two variables
h) To find the distance between two points.
AMU
AMU
CSD
conditions.
PROBLEMS
S
1# Based on the previous scenario, do the followings:
a) Write a friend function to determine number of hours taught by a particular
teacher.
b) Write a program to store details of Teacher, Program and Student, each in a
separate file.
c) Write a program to read details of Student from file whose Roll No is given by
the user?
2# Write a program to find the greatest of three numbers.(use only if Statement)
3# Write a program to find smallest of three number.(use if and else statement)
4# Write a program to check the given no that is even or odd.(use if and else)
5# Write a program to check a year for leap year.( use if and else)
AMU
AMU
CSD
AMU
AMU
CSD
PROBLEMS
S
1# Write a function in C to swap two numbers using function template. The
numbers could be Integer or float that depends on the user inputs.
2# Create a class Matrix that has matric data members and getvalue(), setvalue()
as member functions. Write a program in C to perform Matrix operations (2-D
array implementation), Add and Multiplication using class template.
3# Write a program in Python to check a number for Armstrong. (while)
4# Write a program in Python to print factorial of a number.(for)
5# Write a program in Python to generate first n Fibonacci terms
recursively.(function)
6# Write a program in Python to compute factorial of an integer n
recursively.(function)
AMU
AMU
CSD
CSD
PROBLEMS
S
1# Write a C program to search an element in a given 2D array of integers.
CSD
AMU
AMU
CSD
.
After completing this, the students would be able to:
using C.
to construct lists and access items in those lists.
to use methods to manipulate lists.
to perform traversals of lists to process items in the lists
to define simple functions that expect parameters and return
values.
PROBLEMS
S
1# Write a C Program to sort a given list of Integers using Bubble sort technique.
3# Write a Python program to create an array of 5 integers and display the List
items. Access individual element through indexes.
4# Write a Python program to reverse the order of the items in the array.
CSD
a) Write a program that prints out all the elements of the list that are less
than 5.
b) Instead of printing the elements one by one, make a new list that has all
the elements less than 5 from this list in it and print out this new list.
c) Ask the user for a number and return a list that contains only elements
from the original list a that are smaller than that number given by the user.
8# Let‟s say I give you a list saved in a variable: a = [1, 4, 9, 16, 25, 36, 49, 64,
81, 100]. Write one line of Python that takes this list a and makes a new list
that has only the even elements of this list in it.
15# Write a function called most_frequent that takes a string and prints the letters
in decreasing order of frequency. Find text samples from several different
languages and see how letter frequency varies between languages.
AMU
AMU
CSD
.
OUTCOMES
PROBLEMS
S
1# Write a C Program to sort a given list of Integers using Insertion sort technique.
2# Write a C Program to sort a given list of Integers using Quick sort technique.
3# Assume that the variable data refers to the dictionary {“b”:20, “a”:35}.
data[“a”]
data.get(“c”, None)
len(data)
data.keys()
data.values()
data.pop(“b”)
AMU
AMU
CSD
a) Replace the value at the key “b” in data with that value‟s negation.
5# Write a python program to read a string and count how many times each letter
appears. (Histogram)
6# Write a python program to create a dictionary, read a value from the user and
search the key element (Reverse lookup).
AMU
AMU
CSD
PROBLEMS
S
1# Write a C program to create a Linked List and perform the following
operations:
2# Write a C program to append a Linked List L2 into a given Linked List L1. L1
contains N1 nodes with header H1 and L2 contains N2 nodes with header
H2.
AMU
AMU
CSD
AMU
AMU
CSD
PROBLEMS
S
1# Write a C program that reverses a given list L with header H while traversing it
only once. Each node should point to the node that was previously its
predecessor; the head should point to the node that was previously at the end
and the node that was previously at beginning should be last node.
2# Write a C program to implement circular doubly linked list and perform the
following operations:
CSD
.
OUTCOMES
PROBLEMS
S
1# Write a C program to create a Stack and perform the following operations:
CSD
PROBLEMS
S
1# Write a C program to check whether an expression has balanced parentheses
using array implementation of a stack.
AMU
AMU
CSD
PROBLEMS
S
1# Write a C program to create a Queue and perform the following operations:
2# Write a C program to move all the items from a queue onto stack.
AMU
AMU
CSD
PROBLEMS
S
1# Write a C program to implement Binary tree insertion.
CSD
functions.
PROBLEMS
S
1# Write a C program to implement graph using array and linked-list.
2# Write a C program to implement Breadth-First and Depth-First Traversal of
Graphs.
3# Write a C program to implement Dijkstra‟s Single Source Shortest Path
Algorithm.
AMU
AMU
CSD