100% found this document useful (1 vote)
728 views5 pages

Python Lab List (Final)

The document outlines a list of experiments for a course on Programming Using Python. It includes experiments involving loops, functions, strings, tuples and dictionaries, data structures, classes, files, and graphics and image processing. The experiments cover a range of Python programming concepts like pattern printing, string manipulation, data structures, object-oriented programming, file I/O, and image processing.

Uploaded by

Pooja Garv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (1 vote)
728 views5 pages

Python Lab List (Final)

The document outlines a list of experiments for a course on Programming Using Python. It includes experiments involving loops, functions, strings, tuples and dictionaries, data structures, classes, files, and graphics and image processing. The experiments cover a range of Python programming concepts like pattern printing, string manipulation, data structures, object-oriented programming, file I/O, and image processing.

Uploaded by

Pooja Garv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Department of Computer Engineering

B.Tech (Computer Engineering / Information Technology)

COURSE TITLE: PROGRAMMING USING PYTHON


COURSE CODE: CSPE-22 / ITPE-22

LIST OF EXPERIMENTS

LOOPS

1. Write a Python program which accepts a sequence of comma separated 4 digit binary numbers as
its input and print the numbers that are divisible by 5 in a comma separated sequence.
Sample Data : 0100,0011,1010,1001,1100,1001
Expected Output : 1010

2. Write a Python program that accepts a string and calculate the number of digits and letters.
Sample Data : Python 3.2
Expected Output :
Letters 6
Digits 2

3. Write a Python program to print alphabet pattern 'X'.


Expected Output:
* *
* *
**
*
**
* *
* *

4. Write a Python program to print alphabet pattern 'Z'.


Expected Output:
*******
*
*
*
*
*
*******

FUNCTIONS

1. Write a Python function to multiply all the numbers in a list.


Sample List : (8, 2, 3, -1, 7)
Expected Output : -336

2. Write a Python program to reverse a string.


Sample String : "1234abcd"
Expected Output : "dcba4321"

3. Write a Python function to calculate the factorial of a number (a non-negative integer). The
function accepts the number as an argument.

4. Write a Python function to check whether a number is in a given range.

5. Write a Python function that accepts a string and calculate the number of upper case letters and
lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12

6. Write a Python function that takes a list and returns a new list with unique elements of the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]

STRINGS

1. Write a Python program to calculate the length of a string.

2. Write a Python program to count the number of characters (character frequency) in a string.
Sample String : ‘google.com'
Expected Output : {'o': 3, 'g': 2, '.': 1, 'e': 1, 'l': 1, 'm': 1,
'c': 1}

3. Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string.
If the string length is less than 2, return instead of the empty string.
Sample String : 'w3resource'
Expected Result : 'w3ce'
Sample String : 'w3'
Expected Result : 'w3w3'
Sample String : 'w'
Expected Result : Empty String

4. Write a Python program to get a string from a given string where all occurrences of its first char
have been changed to '$', except the first char itself.
Sample String : 'restart'
Expected Result : 'resta$t'

5. Write a Python program to get a single string from two given strings, separated by a space and
swap the first two characters of each string.
Sample String : 'abc', 'xyz'
Expected Result : 'xycabz'

6. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the
given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is
less than 3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'

7. Write a Python program to find the first appearance of the substring 'not' and 'poor' from a given
string, if 'not' follows the 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the
resulting string.
Sample String : 'The lyrics is not that poor!'
'The lyrics is poor!'
Expected Result : 'The lyrics is good!'
'The lyrics is poor!'

8. Write a Python function that takes a list of words and returns the length of the longest one.

TUPLES AND DICTIONARIES

1. Write a Python script to sort (ascending and descending) a dictionary by value.

2. Write a Python script to add a key to a dictionary.


Sample Dictionary : {0: 10, 1: 20}
Expected Result : {0: 10, 1: 20, 2: 30}

3. Write a Python script to concatenate following dictionaries to create a new one.


Sample Dictionary :
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

4. Write a Python script to check if a given key already exists in a dictionary.

5. Write a Python program to iterate over dictionaries using for loops.

6. Write a Python program to slice a tuple.

7. Write a Python program to find the index of an item of a tuple.

8. Write a Python program to find the length of a tuple.

9. Write a Python program to convert a tuple to a dictionary.

DATA STRUCTURES

1. Write a Python program for binary search.

2. Write a Python program to sort a list of elements using the insertion sort algorithm.
Sample Data: [14,46,43,27,57,41,45,21,70]
Expected Result : [14, 21, 27, 41, 43, 45, 46, 57, 70]

3. Write a Python program to sort a list of elements using the merge sort algorithm.

4. Write a Python program to sort a list of elements using the quick sort algorithm.
5. Write a Python program to create a queue and display all the members and size of the queue.
Expected Output: Members of the queue:
0 1 2 3
Size of the queue:
4

6. Write a Python program to find whether a queue is empty or not.

7. Write a Python program to create a LIFO and a FIFO queue.

8. Write a Python program to solve the Fibonacci sequence using recursion.

CLASSES

1. Write a Python class to find the three elements that sum to zero from a set of n real numbers.
Sample Input array : [-25, -10, -7, -3, 2, 4, 8, 10]
Expected Output : [[-10, 2, 8], [-7, -3, 10]]

2. Write a Python class to implement pow(x, n).

3. Write a Python class to reverse a string word by word.


Sample Input string : 'hello .py'
Expected Output : '.py hello'

4. Write a Python class which has two methods get_String and print_String. get_String accept a string
from the user and print_String print the string in upper case.

5. Write a Python class named Rectangle constructed by a length and width and a method which will
compute the area of a rectangle.

6. Write a Python class named Circle constructed by a radius and two methods which will compute
the area and the perimeter of a circle.

7. Write a python Program to create a base class Person, which represents any person associated with
a university. Then create a subclass to representstudents and one to represent staff members, and
then a subclass of Staff Member for people who teach courses.

8. Write a python Program to illustrate the concept of Operator Overloading.

FILES

1. Write a Python program to read an entire text file.

2. Write a Python program to read first n lines of a file.

3. Write a Python program to append text to a file and display the text.

4. Write a Python program to read last n lines of a file.

5. Write a Python program to read a file line by line and store it into a list.

6. Write a Python program to read a file line by line and store it into a variable.
7. Write a Python program to read a file line by line and store it into an array.

8. Write a Python program to find the longest words.

9. Write a Python program to count the number of lines in a text file.

10. Write a Python program to count the frequency of words in a file.

GRAPHICS & IMAGE PROCESSING

1. Write Python programs to draw an image, to examine its width and height, to return a tuple of the
RGB values at the given coordinates, to replace an RGB value at a given position in the imageand
to save the image.

2. Write Python programs to rotate an image, to convert an image from color to grayscale and to
convert an image from color to black and white.

3. Write Python programs to blur all or part of an image and to sharpen all or part of an image.

4. Write a Python program to reduce the size of an image.

You might also like