0% found this document useful (0 votes)
7 views6 pages

Python Lab

The document outlines a series of programming assignments covering various topics in Python, including algorithms, arithmetic operations, control structures, data structures, file handling, exception handling, and data analysis. Each assignment includes specific tasks such as writing functions, implementing sorting algorithms, and creating plots. The assignments are structured progressively, from basic operations to more complex data manipulation and visualization techniques.

Uploaded by

deyananya533
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)
7 views6 pages

Python Lab

The document outlines a series of programming assignments covering various topics in Python, including algorithms, arithmetic operations, control structures, data structures, file handling, exception handling, and data analysis. Each assignment includes specific tasks such as writing functions, implementing sorting algorithms, and creating plots. The assignments are structured progressively, from basic operations to more complex data manipulation and visualization techniques.

Uploaded by

deyananya533
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

1.

Write the algorithm, draw the flowchart, and write pseudo code for:
o Adding two numbers entered by the user.
o Finding the area of a triangle given its base and height.
o Calculating simple interest.
2. Write a Python program to assign values to variables a = 10, b = 5, and:
o Add, subtract, multiply, divide a and b, and print the results.
o Show the use of arithmetic, logical (and, or, not), and comparison
operators.
o Demonstrate operator precedence using an expression like a + b * 2 - (a /
b).
3. Write a Python program to: o Accept user name and age from input. o Print
a greeting message including both.
4. Write a Python program to:
o Accept two integers from the user and perform arithmetic operations on
them.
o Show the use of input(), int(), print(), and string formatting.
5. Demonstrate the difference between:
o Left-hand side (LHS) and right-hand side (RHS) in assignment. How examples
like x = 5, x = x + 2, y = x * 3.

AS-2
1. Write a program to check whether a number is even or odd.
2. Write a program to determine whether a number is positive, negative, or
zero.
3. Program to find the greatest among three numbers.
4. Check whether a year entered by the user is a leap year.
5. Student grade calculator:
• If percentage > 85 → A grade
• 75 ≤ percentage ≤ 85 → B grade
• 50 ≤ percentage < 75 → C grade
• 30 ≤ percentage < 50 → D grade
• percentage < 30 → Fail

AS - 3
1. Write a program to print the first N natural numbers using a for loop.
2. Write a program to calculate the factorial of a number using a while loop.
3. Demonstrate the use of break, continue, and pass in separate programs: •
Exit a loop early using break. • Skip printing a specific number using continue. •
Use pass in a loop body placeholder.
4. Program to print patterns using nested loops:
*
**
***
5. Reverse triangle:
***
**
*
6. Print numbers in steps of 5 between 0 and 50 using range().
7. Use range() to create countdown from 10 to 1.

AS - 4
1. Create a list of integers from 1 to 10.
2. Perform:
append(), insert() operations.
Update and delete specific elements using index and value.
Sort and reverse the list.
Slice the list (e.g., first 5 elements, every second element).
Use list comprehension to generate a list of squares of even numbers.
3. Create tuples with:
Mixed types (e.g., (1, "Python", 3.14)),
Single-element tuple: (5,),
Nested tuples: (1, (2, 3), 4).
4. Demonstrate:
Tuple unpacking,
Access by indexing,
Methods like count() and index().
5. Create a set from a list with duplicates.
6. Apply:
add(), remove() methods,
union(), intersection(), difference() with other sets.
7. Use set comprehension to find squares of numbers divisible by 3.

AS - 5
1. Implement the selection sort algorithm in Python.
2. Display the selection and swapping process clearly.
3. Allow user input for the list to be sorted.
4. Implement the bubble sort algorithm in Python.
5. Show intermediate steps of each iteration.
6. Sort the same list and compare results with selection sort.
7. Show sorted outputs side-by-side.
8. Discuss performance or iteration count differences in comments.
As 6
1. Define a function to calculate the square of a number (using positional
argument).
2. Define a function for the area of a rectangle with a default value for breadth.
3. Define a function using keyword arguments to print employee details.
4. Write a function that returns both sum and product of two given numbers.
5. Write the following using recursive functions:
a) Factorial of a number.
b) nth Fibonacci number.
c) Power calculation (x^n)

as 7
1) Write a Python program to:

a) Open a text file in write mode and write some data into it.

b) Read and print the contents using the read() method.

c) Close the file properly and print a message once closed.

2) Open a file in different modes (r, w, a, r+) and print file attributes like:

a) name, mode, closed, readable(), writable(). 3) Write a program to:

a) Create a file named [Link].


b) Add student name and marks.
c) Append additional student records without overwriting existing
content.
4) Demonstrate:
a) Use of tell() to get the current file pointer.
Use of seek() to move the pointer and read data from a specific position.
As 8
1) Create a file [Link] and copy its content into [Link].
2) Rename [Link] to data_backup.txt.
3) Create a directory called logs, and inside it:
Create a file [Link].
Write log entries into it.
Delete [Link] and then remove the logs directory.

AS-9
1) Write programs to demonstrate exception handling for:
a) Division by zero.
b) Invalid file access (e.g., opening a non-existent file).
c) Handling ValueError during type conversion.
2) Write a program to:
a) Prompt user input.
b) Perform a calculation inside try.
c) Handle error in except.
d) Print a final cleanup message in finally regardless of success or failure.
3) Create a program with try block that can raise multiple exceptions and
handle them using different except blocks (e.g., IndexError, TypeError,
FileNotFoundError).

AS-10
1. Reading Data
• Read .csv or .xlsx files using pd.read_csv() or pd.read_excel().
• Display column headers, dataset shape, and summary.
2. Data Cleaning
• Handle missing values using fillna() and dropna().
• Convert data types where necessary.
3. Data Filtering and Aggregation
• Filter data based on conditions (e.g., select rows with marks > 75).
• Use groupby() and agg() to summarize data.

AS-11
1. Plotting Graphs
• Create the following plots with proper titles and labels:
o Scatterplot
o Line plot
o Bar plot
o Histogram
o Box plot
o Pair plot (using seaborn)
2. Styling and Subplots
• Customize plots with colors, legends, and markers.
• Use subplot() to plot multiple graphs in one figure.

You might also like