Programming in Python
1) Given two integers x and n, compute 𝑥n
2) To calculate perimeter/circumference and area of shapes such as triangle(a,b,c are
sides), rectangle, square and circle. –MENU DRIVEN
3) Calculator +, - , *,(/,//, %) performed only if divisor is not Zero
4) Input two numbers and display the larger / smaller number.
5) Input three numbers and display the largest / smallest number.
6) Input three numbers and display them in ascending order.
7) To calculate Simple and Compound interest – menu driven
SI=prt/100 -Simple interest
A=P(1+r/n)nt
Where:
• A= the amount of money accumulated after n years, including interest.
• P = the principal amount (the initial sum of money).
• r = the annual interest rate (in decimal form, so 5% becomes 0.05).
• n = the number of times that interest is compounded per year.
• t= the number of years the money is invested or borrowed for.
8) Temperature conversion – menu driven
9) Display the factors of a number n
10) Write a program to input the value of x and n and print the sum of the following
series:
𝑥1 𝑥2 𝑥3 𝑥𝑛
i. 𝑥+ − + −⋯±
2! 4! 6! 2𝑛!
1! 3! 5! 2𝑛−1!
ii. 1 − + − + ⋯ . ±.
𝑥2 𝑥4 𝑥6 𝑥 2𝑛
𝑥 𝑥3 𝑥5 𝑥 2𝑛−1
iii. 1 + + + + ⋯..+
1! 2! 3! (𝑛)!
𝑥2 𝑥4 𝑥6 𝑥 2𝑛
iv. − + − ⋯±
1! 3! 65! 2𝑛−1!
11) Input a number and check if the number is a prime or composite number.
12) Display all the prime numbers in a range
13) Compute the greatest common divisor and least common multiple of two integers.
Use while loop for 15 to 17
14) Display the Fibonacci series from 1,1…. to n.
15) Display the sum of digits and reverse of an integer number n.
16) Determine whether a number is a perfect number, an Armstrong number or a
palindrome.
17) Display all Armstrong numbers in a range.
18) Count and display the number of vowels, consonants, uppercase, lowercase
characters in string.
1
19) Input a string and determine whether it is a palindrome or not; convert the case of
characters in a string.
20) Write a user defined function in Python named Puzzle (W,N) which takes the
argument w as an English word and N as an integer and returns the string where every
Nth alphabet of the word wis replaced with an underscore ("_").
For example: if w contains the word "TELEVISION" and N is 3, then the function should
return the string "TE_EV_SI_N". Likewise for the word "TELEVISION" if N is 4, then the
function should return "TEL_VIS_ON".
21) Write a user-defined function Traverse( ) that processes a list of strings to produce
the following output:
• If an element contains both alphabets and numbers, display it three times.
• If an element contains only alphabets, display it terminated with a ‘#’.
For example, if the content of the list is as follows:
[‘41a’,’DROND’,’GIRIRAJ’,’13B’,’ZARA’]
The output should be
41a41a41a
DROND#
GIRIRAJ#
13B13B13B
ZARA#
22) Write user defined functions to display
a) smallest number
b) largest number
in a list without built in min() & max()
23) Input a list of numbers and swap elements at the even location with the elements at
the odd location.
24) Input a list/tuple of elements, display whether a given element in the list/tuple. If
element doesn’t exist, display an appropriate message.
25) Input a list of numbers and test if a number is equal to the sum of the cubes of its
digits. Find the smallest and largest such number from the given list of numbers.
26) Write a user defined function to accept a decimal number n(base 10 number) and a
base number b (either 2,8,16) and display n’s equivalent to any base input by the
user and display the converted number(either binary or octal or hexa decimal)
If n is 3 and b is 2, then display 3’s equivalent binary number 11.
27) Write a program to read a list of elements. Modify this list so that it does not contain
any duplicate elements i.e., all elements occurring multiple times in the list should
appear only once.
2
28) Write a user defined function change(L) to accept a list of numbers and replace the
numbers in the list with their sum of digits.
Sample Input : [32,142,215,26,7]
Output : [5, 7 , 8 , 8, 8,7]
29) Write a user defined function in python to SwapHalfList(Array), which accepts a list
Array of numbers and swaps the elements of 1st Half of the list with the 2nd Half of
the list ONLY if the sum of 1st Half is greater than 2nd Half of the list.
Sample List: [ 100, 200, 300, 40, 50, 60]
Output : [40, 50, 60, 100, 200, 300]
30) Write a menu driven program to perform the following operations on a nested list:
a) to add items with employee’s id, name and salary
sample:
[(101,‘Meera’,20000],[102,Megan’19000],………]
b) Display the details of all employees in tabular format.
c) Modify the salary of specified employee
d) Increment the salary by 1000 of all employees if salary less than 12000.
e) Delete a particular employee
f) Check if an employee is present not.
31) Create a dictionary with the roll number, name and marks of n students in a class and
display the names of students who have marks above 75.
32) Write user defined functions to accept a string as its argument display
a) n most repeated characters
b) n common word with its frequency
33) Consider the following data format:
{101: { "John": 24500}, 102: {"Andrew": 26000},103:{ "Mark":26200},
104:{"Peter": 25800 },…..}
Write menu driven program to perform the following operations:
a) create/add records in dictionary
b) Search and display a particular employee’s details
c) modify salary of a particular employee
d) increase salary of employees whose salary less than 25000 by 1500.
e) delete a particular employees record
f) display all employees records in tabular form
34) Consider the following:
emp = {"John": { "January": 4500, "February": 5200, "March": 4800 },
"Emily": {"January": 6000,”February": 6200,"March": 5800 },…..}
Write Python user defined functions to:
a. Increase the sales by 10% for employees whose average sales exceed 6000.
3
b. Identify the month in which each employee had their highest sales.
c. Display the details of those employees whose name begin with a vowel.
35) Consider the following student data:
data = [ ["Alice", 101, [85, 78, 92, 89]], ["Bob", 102, [76, 85, 90, 80]],
["Charlie", 103, [92, 88, 94, 91]], ["David", 104, [60, 72, 70, 65]],…..]
Write Python user defined functions to:
a) Calculate and display each student's average marks.
b) Identify and display the students who have scored below 70 in any subject.
36) Consider the following data format:
{101:['Andrew',78],102:['Mark',99],103:['John',100],...}
Write user defined functions to:
a) Create a dictionary with the roll number, name and marks of n students in a class.
b) display the names of students who have marks above 75.
37) Create a database CS_21_22 and open it.
38) Create a student table with the student id, name, and marks in five subjects
(Eng, Phy, Che, Maths, CS)
a. Add columns Tot and Grade
b. Update Tot using query.
c. Update Grade using queries(s).
d. Delete the details of a student in the above table whose mark not assigned.
e. Display the details of the students with average mark more than 80.
f. Display the name
g. Display the min, max, sum, and average of the marks.
h. Order the (student ID, Name &marks) table in descending order of the marks.
i. Add the record - 's104','Catherine', 95,76, NULL, 74, 63.
j. Change Che =80 and Grade =’A’ for the student with id s104.