0% found this document useful (0 votes)
3 views12 pages

Python Programming Aman

Uploaded by

kartiqksharma
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)
3 views12 pages

Python Programming Aman

Uploaded by

kartiqksharma
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

ASSIGNMENT

Python programming
Part A – Short Answer Questions (20 Marks)

1) Explain the Zen of Python and its importance in


writing Python code.

ANSWER:-

Zen of Python is a collection of guiding principles for


writing clean, readable, and efficient Python code.
You can view it using:

Importance:
Encourages clarity and simplicity.
Makes collaborative coding easier.
Helps write industry-standard Pythonic code.
Reduces bugs and improves maintainability.
2) Differentiate between lists, tuples, sets, and
dictionaries with suitable examples.

ANSWER:-

Ordered Mutable Duplicate Example


Type ?
? Allowed?

List yes yes yes [1, 2, 2, 3]

Tuple yes no yes (10, 20, 20)

Set no yes no {1, 2, 3}

Keys: No order
Dictionary (Py3.7+ ordered),
Values mutable
keys are unique
no {"name":"Ajay",
"age":20}
3)What is exception handling in Python? Explain with an
example.

ANSWER:-

Exception handling manages runtime errors so the


program does not crash.
4) Write a short note on NumPy broadcasting with an
example.

ANSWER:-

Broadcasting allows NumPy to perform operations on


arrays of different shapes by automatically expanding
smaller arrays.
Part B – Programming Questions (50 Marks)

5) Write a Python program to input a number and check


whether it is prime or not.

ANSWER:-
6) Write a program to display the Fibonacci
sequence up to n terms using recursion.

ANSWER:-
7)Create a function in Python that accepts any
number of keyword arguments and prints them
in a dictionary format.

ANSWER:-
8)Write a Python program to demonstrate file
handling by performing the following: Create a
file named [Link] ;Write the names of 5
students into the file ; Read and display the
contents of the file

ANSWER:-
9)Write a Python class BankAccount with the
following :
1. Attributes: account_number, balance
2. Methods: deposit(), withdraw(),
display_balance() Demonstrate the working
of the class by creating an object and
calling the methods. (

ANSWER:-
10)Write a Python program using Pandas to
create a DataFrame from a dictionary of
student data (Name, Age, Marks). Perform the
following operations:

Display the DataFrame


Sort the DataFrame by Marks in
descending order
Filter students with Marks greater than 80

ANSWER:-
Part C – Applied Problem-Solving (30 Marks)

11) 11. Data Analysis Project with NumPy and Pandas


You are given the following student score data: import
numpy as np import pandas as pd

data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],


'Maths': [78, 95, 62, 88, 70],
'Science': [84, 90, 59, 76, 92],
'English': [85, 87, 74, 90, 65] }

Perform the following tasks:

1. Create a Pandas DataFrame from the given data.


2. Calculate the average score of each student.
3. Find the student with the highest average score.
4. Add a new column Result where students scoring an
average of 75 or above are marked as “Pass”, else “Fail”
.5. Display summary statistics of the DataFrame.
6. Plot a bar chart comparing students’ average scores
using Pandas/Matplotlib.

ANSWER:-

You might also like