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

Assignment 3 and 4

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)
6 views2 pages

Assignment 3 and 4

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
You are on page 1/ 2

Assignment 3

Attempt ALL Questions


1. Write a python program to find factorial of a number using Recursion.
2. Given a list of numbers, express a python function that finds the third largest number in the
list.
3. Write the code to perform following operations on the list
L1=[12,23,23,56,67,24]
a. find number of elements in the list
b. remove 3rd element
c. add 33 at index position 0
d. add 99 at the end of the list
e. search for `67' in the list and if it exists print its index position.

4. Write a Python function to find the maximum of three numbers.


5. You are provided with following data consisting of grocery items and their cost.
price = [('item1', '17.20'), ('item2', '15.10'), ('item3', '24.5')]
sort the above data on the basis of price and display it in order.
Which item is the second costliest in the list?
6. You are provided with a list of tuples containing coordinates of 2D points as shown below
Data= [(1,2), (3,4), (5,6), (7,8)]
Write a program to separate the x and y coordinates and store them in separate tuples.
Output [(1,3,5,7), (2,4,6,8)]
7. Write a program in python to print middle elements of a list and tuple.
8. Describe the benefits and limitations of using dictionaries over lists for data storage in
python, providing examples to support your points.
9. Write a program in python to:
a) Create a dictionary
b) Add an element to dictionary
c) Access dictionary elements
d) Remove an element of dictionary
e) Update the element of the dictionary

10. Define an anonymous function (lambda function) that squares a given number. Use the
lambda function to square the numbers 1 to 5 and print the results.
Assignment 4
Attempt ALL Questions
1. What are different file modes in file handling? Explain
2. Differentiate functions write() and writelines() in regard to file handling using an
example.
3. Differentiate functions read(), read(20) readline() and readlines () in regard to file
handling using an example.
4. Write a Python program to create a new file.
5. Write a Python Program to Write Content in the file.
6. Write a Python Program to delete the file.
7. Write a Python Program to Copy the content from one file A to another file B using
Exception Handling.
8. Write a Python script that attempts to open a non-existent file. Use the try and except
clauses to handle the FileNotFoundError and print a custom error message.
9. Perform the following operations on the file:
a) Read and print the first 10 characters
b) Move to the 20th character
c) Read and print the next 15 characters
d) Move 10 characters back from current position
e) Read and print the next 10 characters
f) Move to the beginning of the file
10. Explain with an example how the seek () function works, including its arguments and
how it affects file reading/writing.

You might also like