0% found this document useful (0 votes)
6 views10 pages

Python_MB-2_sec-09 (1)

The document outlines an assessment for a Python programming course, focusing on various operations using NumPy and Pandas. It includes tasks such as creating and manipulating 2D arrays, handling exceptions, designing a food rating system, and performing file operations. Additionally, it emphasizes the implementation of user-defined modules and data analysis using CSV files.

Uploaded by

nandinivemula229
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views10 pages

Python_MB-2_sec-09 (1)

The document outlines an assessment for a Python programming course, focusing on various operations using NumPy and Pandas. It includes tasks such as creating and manipulating 2D arrays, handling exceptions, designing a food rating system, and performing file operations. Additionally, it emphasizes the implementation of user-defined modules and data analysis using CSV files.

Uploaded by

nandinivemula229
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

M2 - T1 Assessment

Course: PYTHON PROGRAMMING


I CSE-09 Faculty Name: Mrs M.Sumalatha
PART-A

1. Create the following 2D array using Numpy and perform below operations:

2 3 4 5 6
10 11 12 13 14
18 19 20 21 22
26 27 28 29 30
31 33 34 35 36
37 38 39 40 41

a) Write the code routine to print the masked (gray) colored sub-array
b) Print the maximum of the fifth row.
c) Reshape the array (change columns to rows, rows to columns)
d) Extract all the odd number using conditional logic
e) Find the column wise mean, std and variance
f) Add a new row
g) Delete an existing column
h) Replace a specific value
i) Identify how many values are less than given x
2. Design and develop the solution for the following problem.
Create a 2D Numpy array with 20 elements of size 5x4 and perform the following
operations using Numpy arrays: [NumPy package]
a. Retrieve the last two row values
b. Retrieve the sum of the second-row values
c. Display the max value index in the array.
d. Add a new row
e. Replace a specific value
f. Identify how many values are less than given x
g. Identify unique values in the array
3.a) Read the students details like RegNo (alphanumeric), Name(string), Age(int), marks(float)
from the user and store the data in a data structure and display the details of a particular
student based on RegNo.By Using exception handling handle the exception when the
user inputs different type of data rather than specified data.
b)Design a calculator, the input consist of a number, an operator (at least + and -), and
another number, separated by white space (e.g. 1 + 1).
 If the input does not consist of 3 elements, raise a Argument Error, which is a
custom Exception.
 The first and the third input must be positive numbers other than that raise Not positive
exception
 If the second input is not '+' or '-', again raise a Operator Error (custom exception)

If the input is valid, perform the calculation and print out the result. The user is then
prompted to provide new input, and so on, until the user enters quit.
c) Design a food rating system of a Restaurant
The items in the restaurant are Solid type food[biryani,noodles,manchuria],Semi liquid
food[icecreams,soups] and liquid food [fruit juices,cooldrinks]
Solid Food ratings:Best,Good,Average,poor
Semi liquid ratings:1-5
Liquid ratings:1.0-5.0
For every customer we need to collect all the ratings, if customer gives float value ratings
to solid food we need to raise error ,the same follows for all ratings, Use exception handling
to prevent the system from halting
4. Design and Implement the following operations.
a. Create a 1D array and append a new element to the end.
b. Normalize the columns of a 2D array to have a sum of 1
c. Write a Pandas program to convert a NumPy array to a Pandas series.
NumPy array:
[10 20 30 40 50]
Converted Pandas series:
0 10
1 20
2 30
3 40
4 50
d. Write a Python programming to create a pie chart of the popularity of programming
Languages.
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
5. Create a module called file operations to perform the following file handling operations.
a) Compare (): to compare the contents of two files
b) Capitalize (): capitalize the first letter of every word
c) Remove (): remove an empty directory
d) Create (): create a directory
e) List_of_files (): list of files and sub directories of the current directory
f) Append (): append the content of one file to another file
g) Search(): Search a file in the directory

Compare the performance of each operation with the existing functions by increasing number
of lines in a file
6. a) Create a user defined module as “Operations” having user defined functions like add(),
sub(),div(),mul(),mod(),cube(),pow(),sqrt(),sin(),cos(),exponentioal()[Note :Don’t use built-in
methods].Access the “Operations” module in a program.py to show the usage of all the
methods of “Operations” module.
b) Using Pandas on Dataset, create a .csv file including 20 rows with the data[Years ,
Experience , Salary]
a. read a .csv file
b. Analyze the data
c. export and plot the results
c) Write a Python programming to display a bar chart of the popularity of programming
Languages. Use different color for each bar.

Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
7. Design and Implement the following
a. Write a NumPy program to create a 2-D array whose diagonal equals [4, 5, 6,
8] and 0's elsewhere.
Expected Output:
[[4 0 0 0]
[0 5 0 0]
[0 0 6 0]
[0 0 0 8]].
b. Write a NumPy program to collapse a 3-D array into a one-dimensional array.
Expected Output:
3-D array:
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
One dimension array:
[ 1. 0. 0. 0. 1. 0. 0. 0. 1.].
c. Write a Pandas program to select a row of series/dataframe by given integer
index.
Original Data Frame
col1 col2 col3
0 1 4 7
1 4 5 8
2 3 6 9
3 4 7 0
4 5 8 1
Index-2: Details
col1 col2 col3
2 3 6 9

d. Write a Python program to draw a scatter plot comparing two subject marks of
Mathematics and Science. Use marks of 10 students.

math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
8. Design and develop functions on the files. Consider two files File1 and File2, perform the
following operations.

a. Copy the contents of File1 to File2

b. Concatenate the two files and copy the content into File3

c. Remove the duplicate lines in File3

d. Print all the even lines and odd lines in File3

e. Print all the odd lines in File3 f. Extract all the characters from File1, File2 and File3
9. a) Create a binary NumPy array (containing only 0s and 1s) and convert a binary NumPy
array to a Boolean NumPy array
b) You will build an application that will flip a coin 20 times, keep a running total of heads
and tails. For each coin toss, you will display the result (heads or tails). After the last toss,
you will display the total number of heads, total number of tails and the percentage of each.
c) Design a food rating system of a Restaurant
The items in the restaurant are Solid type food [biryani, noodles, Manchuria], Semi liquid
food [ice-creams, soups] and liquid food [fruit juices, cool drinks]
Solid Food ratings : Best, Good, Average, poor
Semi liquid ratings:1-5
Liquid ratings:1.0-5.0
For every customer we need to collect all the ratings, if customer gives float value ratings
to solid food we need to raise error , the same follows for all ratings, Use exception
handling to prevent the system from halting
10. Design and Develop the solution for the following. By importing numpy package, Read
name, regd no, percentage of n students and do the following operations
a. Sort the details by using name
b. Sort the details by using name and percentage
c. Details of a student who got highest percentage
d. Details of a student who got least percentage
e. Find average marks obtained by specified student

You might also like