Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ATSS’s

Institute of Industrial & Computer Management & Research, Nigdi.


Academic year – 2020-2021
MCA I – Semester –II
LAB Exercise
Subject : Python Programming - LAB (IT-21L )

Sr.
Name Of Program
No.
Threading and Multithreading :
1. Write A program to demonstrate:
A. Creating a Thread without using any class
B. Creating a Thread by extending Thread class
C. Creating a Thread without extending Thread class
D. Use of getname(), setname(),isalive(), Join(),enumerate() etc.
E. Deamon Thread.

2. An ABC company wants to perform the following tasks .


A. Copy the contents of ‘FILE1.txt’ to ‘FILE2.txt’
B. Count the number of lines, characters, special symbols for a given file.
Write a python program using multithreading concept to perform above operations
simultaneously. Accept the filenames from user.
1
( HINT : Thread_obj=Thread(target=Func_A , args=(FILE1, FILE2)) where Thread_obj is
thread object , Func_A is function to perform the specific task, FILE1, FILE2 are the file names
passed in the form of tuple as parameter to function.

3. Write a demo Program for synchronization using RLock. Accept the two numbers from
user and calculate factorial of both the numbers.
( Hint : use Rlock(), aquire(), release() methods)

4. Write a program to demonstrate the use of semaphore(n) method with python Multithreading
concept. Accept ‘n’ from user.
( Hint: use Five threads and n is two )
Note : Semaphore can be used to limit the access to the shared resources with limited capacity.

1
File Operation:
1. Write a Python Program to Read the Contents of a text File and display the following information.
a. Total number of characters, digits, special symbols, words, spaces and lines.
b. Path of the current file.
2. Write a program to read the first and last ‘n’ lines of a file. Prompt the user to enter the value for n.
3. Write a program that reads the contents of the file and counts the occurrences of each letter. Prompt
the user to enter the filename.
4. Write Python Program to Read and Print Each Line in "India. txt" file. (use with statement).
5. Write Python program to remove the comment character from all the lines in a given Python source
file.
6. Write Python Program to Reverse Each Word in "data.txt" file.
7. Write Python Program to Find the Longest Word in a File. Get the File Name from User.
8. Write Python Program to Create a New Image from an Existing Image.
9. Write Python Program to Save Dictionary in Python Pickle.
10. Write a Menu driven Python program to write, read and display each row in "marks.csv" CSV file.
2
Sample :

11. Write Python program to write the data given below to a CSV file. Category, Winner, Film,
Year
12. Write a menu driven Python program to Describe the methods available in the os module.

Database Interaction:
Perform the following operations using MongoDB Atlas/Compas/shell
1. Create collection ‘emp’ and insert five documents.
2. Program for performing CRUD (Create , Read, Update, Delete ) operation. Use various methods
3 used for CRUD.
Hint :
1. Insert – insert(), insertOne(), insertMany()
2. Update - update(), updateOne(), updatemany()
3. Read - find()
4. Delete – deleteOne(), deleteMany()

2
Data Analysis:
Numpy:
1. Write a Program to illustrate following numpy array attributes.
ndarray.ndim
ndarray.shape
ndarray.size
ndarray.dtype
ndarray.itemsize
ndarray.data
2. Write a Program to Basic Arithmetic Operations on NumPy Arrays.
3. Write a Program to demonstrative NumPy Arrays Creation Functions: -
np.zeros() Creates an array of zeros
np.ones() Creates an array of ones
np.empty() Creates an empty array
np.full() Creates a full array
np.eye() Creates an identity matrix
np.random. random() Creates an array with random values
4
4. Create two 2-d Numpy Arrays (Matrix A, Matrix B) and perform the following operation on
matrix
a. Addition ( A+B)
b. Multiplication ( AxB)
c. Scalar Multiplication (A x integer or integer x A)
d. Transpose of Matrix

5. Write a Program to perform following using NumPy Arrays.


a. Create a 5-by-5 array of random integers between 0 (inclusive) and 10 (exclusive)
hint - np.random.seed(123) , np.random.randint(0, 10, size = (5,5))
b. Create a sequence of equally gapped 5 numbers in the range 0 to 100 (both inclusive)
c. Convert a 1-D array to a 3-D array
d. Convert all the elements of a numpy array from float to integer datatype
e. Stack two numpy arrays horizontally and vertically i.e., 2 arrays having the same 1st
dimension (number of rows in 2D arrays) – hint use – vstack(), hstack()
f. From two numpy arrays, extract the indexes in which the elements in the two arrays
match ( hint- np.where(a == b))

3
Data Analysis:
(Note: Visit shared folder to download supporting ‘csv’ files.)

Pandas:
Use Automobile Dataset (Automobile_data.csv) and perform following operations for data analysis.
This Dataset has different characteristics of an auto such as body-style, wheel-base, engine-type, price,
mileage, horsepower, etc.

1. From the given dataset print the first and last five rows
2. Find the most expensive car company name
3. Print All Toyota Cars details
4. Count total cars per company
5. Find each company’s Highest price car
5 6. Find the average mileage of each car making company
7. Sort all cars by Price column
8. Apply the rank to the cars average-mileage. ( highest average-mileage – rank 1, so on)

9. Concatenate two data frames using the following conditions


a. GermanCars = {'Company': ['Ford', 'Mercedes', 'BMV', 'Audi'], 'Price': [23845, 171995, 135925 , 71400]}
b. japaneseCars = {'Company': ['Toyota', 'Honda', 'Nissan', 'Mitsubishi '], 'Price': [29995, 23600, 61500 ,
58900]}

10. Create two data frames using the following two Dicts, Merge two data frames, and append the
second data frame as a new column to the first data frame.
a. Car_Price = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'Price': [23845, 17995, 135925 , 71400]}
b. Car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMV', 'Audi'], 'horsepower': [141, 80, 182 , 160]}

Data visualization: use Matplotlib


(Note: Visit shared folder to download supporting ‘csv’ files.)

Use company_sales_data.csv for this exercise.


Read this file using Pandas or NumPy or using in-
built matplotlib function.

Read Total profit of all months and show it using


1. a line plot
Total profit data provided for each month.
Generated line plot must include the following
properties: –
X label name = Month Number
Y label name = Total profit
The line plot graph should look like this.

4
A. Read Total profit of all months and show it
using a line plot
B. Total profit data provided for each month.
Generated line plot must include the following
2. properties: –
I. X label name = Month Number
II. Y label name = Total profit
III. The line plot graph should look like
this.

Read all product sales data and show it using a


multiline plot.
Display the number of units sold per month for
each product using multiline plots. (i.e., Separate
3. Plotline for each product ).

The graph should look like this.

Read toothpaste sales data of each month and


show it using a scatter plot
4. Also, add a grid in the plot. gridline style should
“–“.

The scatter plot should look like this.

Read face cream and facewash product sales data


and show it using the bar chart
The bar chart should display the number of units
5. sold per month for each product. Add a separate
bar for each product in the same chart.

The bar chart should look like this.

6. Read sales data of bathing soap of all months


6. and show it using a bar chart. Save this plot to
your hard disk

5
Read the total profit of each month and show it
7. using the histogram to see the most common profit
ranges
The histogram should look like this.

Calculate total sale data for last year for each


product and show it using a Pie chart
8. Note: In Pie chart display Number of units sold
per year for each product in percentage.

The Pie chart should look like this.

Read Bathing soap facewash of all months and


9. display it using the Subplot
The Subplot should look like this.

Read all product sales data and show it using the


10. stack plot
The Stack plot should look like this.

6
MICRO- PROJECTS ON (Develop min. Two projects )

1) Dice Rolling Simulator


2) Game Board Printing
3) Password Generator
4) Binary Adder
5) Calculator
6) ATM Machine
7) Address Book for your Class
8) Student Performance Analyzer
9) Game 1 – Rock, Papers and Scissors
10) Game 2 – Tic, Tac, Toe

You might also like