Python Paper
Python Paper
2. You have a list of names. Write a Python program to find the length of the longest name in the list.
3. You have a dictionary containing the names and ages of people. Write a Python program to find the average age
of all the people in the dictionary.
4. You have a list of strings. Write a Python program to find the shortest string in the list.
5. You have a list of tuples, where each tuple contains the name and age of a person. Write a Python program to
find the oldest person in the list
6. You have a dictionary containing the names and ages of people. Write a Python program to print the names of all
the people who are older than 18.
7. You are given two numbers, a and b. Write a Python program to swap the values of a and b without using a
temporary variable.
8. You have a string. Write a Python program to count the number of occurrences of a specific character in the
string.
9. You have a list of integers. Write a Python program to remove all the duplicates from the list and create a new
list with unique elements only.
10. You have a string containing a sentence. Write a Python program to convert the sentence into title case, where
the first letter of each word is capitalized.
11. You have a list of dictionaries, each containing information about a person (e.g., name, age, city). Write a
Python program to sort the list of dictionaries by age in ascending order.
12. You have two dictionaries representing the sales data of two different stores, with product names as keys and
sales amounts as values. Write a Python program to merge the two dictionaries and calculate the total sales amount
for each product across both stores.
13. You have a tuple of numbers. Write a Python program to find the maximum and minimum values in the tuple,
and calculate their difference.
14. You are building a car rental system. Write a Python program to create a Car class with attributes such as make,
model, and year, and methods to get and set these attributes.
15. You are building an e-commerce website. Write a Python program to create a Product class with attributes such
as name, price, and quantity, and methods to calculate the total cost of the product based on its price and quantity.
16. Consider the given list try to get an output where first element on each sub-list is in reversed order
I/P : [[1,2,3,4],[5,6,7,8],[9,10,11,12][13,14,15,15]]
O/P:[[13,2,3,4],[9,6,7,8],[5,10,11,12],[1,14,15,16]]
17. You have a string in Python. Write a program to count the number of vowels in the string.
18. You have a list of strings in Python. Write a program to find the longest string in the list.
19. You have a dictionary in Python that contains student names as keys and their corresponding scores as values.
Write a program to find the student with the highest score.
20. You have a list of names in Python. Write a program to sort the names in alphabetical order.
21. You have a list of numbers in Python. Write a program to find the largest and smallest numbers in the list.
22. You have a list of names and you need to create a new list containing only the names that start with a specific
letter.
23. You have a string and you need to count the occurrences of each character in the string.
24. You have a dictionary containing student names and their corresponding scores. You need to find the student
with the highest score.
25. Write a Python program to count the occurrences of each word in a given string.
26. l1=[1,2,3]
l2=[2,3,4]
oup:[3,5,7]
29. Write a program for given Input and produce the following output
I/p: str = 'aaaabbbcc' o/p : 432
32. Write a program to Count No. of occurrences of character in a given string using dictionary
comprehension.(str=”I love My India”)
38. input='A3G4B2'
output= 'ADGKBD'
39. Write a python program for string that will print out char with char count.E.g. c Output should be a4b1a1h5
str1= 'aaaabahhhhhaaa'
40. s='4555&.$@abc'
op=4555
41. s= "name=Dattatray&surname=Tompe&occ=coder"
Output ={'name':'Dattatray' , 'surname':'Tompe' , 'occ':'coder'}
43. a = [ {'name': 'a1' }, {'name': 'a2' }, {'name': 'a3' }, {'name': 'a4' }, {'name': 'a5' } ]
b = [ { 'name': 'a3' }, {'name': 'a5' } ]
O/P: [{'name': 'a3'}, {'name': 'a5'}, {'name': 'a1'}, {'name': 'a2'}, {'name': 'a4'}]
44. Write a Python program to find all the words in the given list whose length is between 5 and 7.
words = *'This', 'is', 'a', 'list', 'of', 'words', 'that', 'contains', 'some', 'technical', 'jargon', 'and', 'abbreviations'+
45. Write a Python program using regular expression to check whether the given string is following below
requirement or not.
I. The allowed characters are a z, A Z, 0 9,#
II. The first character should be a lower case alphabet symbol from a to k
III. The second character should be a digit divisible by 3.
IV. The length of the identifier should be at least 2.
48. s1 = [3, 4, 5, 6, 0]
s2 = [9, 5, 6, 1, 8]
o/p = {(4, 5), (0, 9), (3, 6)}