0% found this document useful (0 votes)
44 views

List of Programs - Python2022

The document contains a list of 80 programming problems ranging from basic Python programs to more advanced concepts involving classes, files, exceptions, NumPy, and pandas. Some example problems include writing a program to draw a scatter plot using random distributions, concatenating dictionaries, removing duplicate values from a list while preserving order, and defining a class to calculate the perimeter and area of a circle.

Uploaded by

chakshu agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

List of Programs - Python2022

The document contains a list of 80 programming problems ranging from basic Python programs to more advanced concepts involving classes, files, exceptions, NumPy, and pandas. Some example problems include writing a program to draw a scatter plot using random distributions, concatenating dictionaries, removing duplicate values from a list while preserving order, and defining a class to calculate the perimeter and area of a circle.

Uploaded by

chakshu agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LIST OF PROGRAMS (FOR REFERENCE)

1 Write a Python program to draw a scatter plot with empty circles taking a random distribution in X and Y and plotted against each other.

2 Write a Python program to draw a scatter plot using random distributions to generate balls of different sizes.
Write a Python program to draw a scatter plot comparing two subject marks of Mathematics and Science. Use marks of 10 students.
3 Sample data: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]
Write a Python script to concatenate following dictionaries to create a new one.
Sample Dictionary :
dic1={1:10, 2:20}
4
dic2={3:30, 4:40}
dic3={5:50,6:60}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
5 Write a Python script to check whether a given key already exists in a dictionary.
Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x).Sample Dictionary
6
( n = 5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
7 Write a Python program to remove a key from a dictionary
8 Write a Python program to map two lists into a dictionary.
Write a Python program to print all unique values in a dictionary
9 Sample Data : [{"V":"S001"}, {"V": "S002"}, {"VI": "S001"}, {"VI": "S005"}, {"VII":"S005"}, {"V":"S009"},{"VIII":"S007"}]
Expected Output : Unique Values: {'S005', 'S002', 'S007', 'S001', 'S009'}
10 Write a Python program to create a dictionary from a string. Note: Track the count of the letters from the string.

Write a program that takes a sentence as an input parameter where each word in the sentence is separated by a space. Then replace each
11
blank with a hyphen and then print the modified sentence. 

12 Write a program to randomly select 10 integer elements from range 100 to 200 and find the smallest among all. 
13 Create a dictionary of 5 countries with their currency details and display them. 
Print as below 
First line
Second line
Third Line
14 Declare complex number , find data type, real part, imaginary part, complex conjugate, absolute value of a number 
15 Change string hello to help  ,remove white spaces before word if  s=”   hello ” 
16 Write a program to randomly select 10 integer elements from range 100 to 200 and find the smallest among all. 
17 Swap first & last letter of a string 
18 Find if substring is present in string or not 
Write a program that takes a sentence as an input parameter where each word in the sentence is separated by a space. Then replace each
19
blank with a hyphen and then print the modified sentence. 
20 WAPP to test whether string is palindrome or not 
21 WAP to capitalize the first character of each words from a given sentence (example: all the best All The Best) 
22 WAP to count the frequency of occurrence of a given character in a given line of text 
23 Create a dictionary of 4 states with their capital details & add one more pair to the same  
24 To count number digits, special symbols from the given sentence. Also count number of vowels and consonants
25 Write a program to accept any string up to 15 characters. Display the elements of string with their element nos 
26 Create a Numpy array filled with all ones 
27 Check whether a Numpy array contains a specified row 
28 Compute mathematical operations on Array, Add & Multiply two matrices
29 Find the most frequent value in a NumPy array 
30 Flatten a 2d numpy array into 1d array 
31 Calculate the sum of all columns in a 2D NumPy array 
32 Calculate the average, variance and standard deviation in Python using NumPy 
33 Insert a space between characters of all the elements of a given NumPy array ['Python' 'is' 'easy']  ['P y t h o n' 'i s' 'e a s y'] 
34 Plot line graph from NumPy array
35 WAP to Reverse a Number 
36 WAP to read number N and print natural numbers summation pattern
37 WAP to determine all Pythagorean triplets 
WAP, You are given a number A which contains only digits 0's and 1's. Your task is to make all digits same by just flipping one digit (i.e.
38
0 to 1 or 1 to 0 ) only. If it is possible to make all the digits same by just flipping one digit then print 'YES' else print 'NO'. 
Given a list A of N distinct integer numbers, you can sort the list by moving an element to the end of the list. Find the minimum number
39
of moves required to sort the list using this method in ascending order  
40 WAP to print following pattern
 1\n 
22\n 
333\n 
4444\n 
55555\n 
666666 
41 Convert two lists into a dictionary 
42 Check how many times a given number can be divided by 6 before it is less than or equal to 10. 
43 Python program to read a file and Capitalize the first letter of every word in the file 
44 Python program that reads a text file and counts number of times certain letter appears in the text file
45 Write a program to write content to file &  append data to file 
46 Python program to read the contents of a file 
47 Copy the contents from one file to another ‘
48 WAP to accept name and roll number of students and store it in file. Read and display the stored data. Also check if file exists or not
49 WAP to copy contents of 1 file to another Let user specify name of source and destination files 
50 Python program to read file word by word 
51 Python program to read character by character from a file 

Page 1 of 2
52 Python – Get number of characters, words, spaces and lines in a file 
53 Make your exception class “InvalidMarks” which is thrown when marks obtained by student exceeds 100  
WAP that accepts the values of a, b, c and d. Calculate and display ((a+d) + (b*c))/ (b*d). create user defined exception to display proper
54
message when value of (b*d) is zero 
Ask user to input an age. Raise an exception for age less than 18 , print message “ age is not valid ” & “age is valid ” if age entered is
55
more than 18   
56 48Handle the FileNotFoundError exception 
57 Raise a TypeError if x is not a string  
Create class Complex , define two methods init to take real & imaginary number & method add to add real & imaginary part of complex
58
number . print addition of real part & addition of imaginary part. 
Create class Triangle, Create object from it . The objects will have 3 attributes named a,b,c  that represent sides of triangle .Triangle class
59 will have two methods init method to initialize the sides & method to calculate perimeter of triangle from its sides . Perimeter of triangle
should be printed from outside the class 
60 Python program to append ,delete and display elements of a list using classe
61 Write a program  to create a class which performs basic calculator operations  
Write a Python class named Student with two attributes student_id, student_name. Add a new attribute student_class. Create a function to
62
display the entire attribute and their values in Student class. 
63 Write a Python class to reverse a string word by word. 
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
64
the string in upper case
65 Write a Python class named Circle constructed by a radius and two methods which will compute the area and the perimeter of a circle. 
Write a Python program to create a Vehicle class with max_speed and mileage instance attributes. Create a child class Bus that will
66
inherit all of the variables and methods of the Vehicle class
67 Load a dataset using pandas : perform basic operations , data visualization using matplotlib ,seaborn etc
68 WAPP to push all zeros to the end of a given list. The order of elements should not change:
Input: 0 2 3 4 6 7 9 0
Output:2 3 4 6 7 9 0 0
69 Write a program that accepts a comma separated sequence of words as input and prints the words in a comma separated sequence after
sorting them alphabetically.
Input: without, hello,bag, world
Output: bag,hello,without,world
70 WAP that calculates & prints value accoridng to given formula:
Q=Square root of [(2*C*D)/H]
C is 50 , H is 30. D is variable whose values should be input to program in comma separated sequence.
Input: 100,150,180
Output:18,22,24

71 With given list L of integers , write a program that prints this L after removing duplicate values with original order preserved.
Input: 12 24 35 24 88 120 155 88 120 155
Output: 12 24 35 88 120 155
Given ab integer number n , define function named printDict(),which can print a dictionary where keys are numbers between 1 to n (both
72
included) and values are square of keys . Function printDict(), does not take any arguments.
73 Python program to find the sum of the digits of an integer using while loop
74 Python program to generate the prime numbers from 1 to N
75 Python program to print the numbers from a given number n till 0 using recursion
Write a Python function student_data () which will print the id of a student (student_id). If the user passes an argument student_name or
76
student_class the function will print the student name and class.
77 Write a Python class to convert a roman numeral to an integer
78 Write a Python class to get all possible unique subsets from a set of distinct integers
Write a Python class to find a pair of elements (indices of the two numbers) from a given array whose sum equals a specific target
79
number
80 Write a Python class to implement pow(x, n).
Write a NumPy program to convert the values of Centigrade degrees into Fahrenheit degrees and vice versa. Values are stored into a
81
NumPy array. Sample Array [0, 12, 45.21, 34, 99.91]
Write a NumPy program to find the set difference of two arrays. The set difference will return the sorted, unique values in array1 that are
82
not in array2
Write a Pandas program to create and display a DataFrame from a specified dictionary data which has the index labels. Go to the editor
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
83 'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'
84 Write a Pandas program to get the first 3 rows of a given DataFrame
85 Write a Pandas program to select the 'name' and 'score' columns from the following DataFrame.
86 Write a Pandas program to select the specified columns and rows from a given data frame.
87 Write a Pandas program to select the rows where the number of attempts in the examination is greater than 2.
88 Write a Pandas program to count the number of rows and columns of a DataFrame.
89 Write a Pandas program to select the rows the score is between 15 and 20 (inclusive).
90 Write a Pandas program to select the rows where number of attempts in the examination is less than 2 and score greater than 15
Write a Pandas program to append a new row 'k' to data frame with given values for each column. Now delete the new row and return the
91
original DataFrame
92 Write a Pandas program to sort the DataFrame first by 'name' in descending order, then by 'score' in ascending order.
93 Write a Pandas program to replace the 'qualify' column contains the values 'yes' and 'no' with True and False.
94 Write a Pandas program to set a given value for particular cell in DataFrame using index value.

Page 2 of 2

You might also like