CS Practical File
CS Practical File
21. Write a program to create a list with inputs from user. Find the largest and smallest
element in the list. Also print the frequency of the smallest element. (There should be
multiple entries of smallest element).
Code:
22. Ask the user to enter a list of strings. Create a new list that consists of those strings
with their first characters removed.
Code:
23. Write a program rotates the elements of a list so that the element at the first index
moves to the second index, the element in the second index moves to the third index,
etc., and the
Code:
25. Write a program to accept values from a user in a tuple. Add a tuple to it and display its
elements one by one. Also display its maximum and minimum value.
Code:
28. Create a tuple ('a', 'bb', 'ccc', 'dddd', ... ) that ends with 26 copies of the
letter z using a for loop.
Code:
29. Given a tuple pairs = ((2, 5), (4, 2), (9, 8), (12, 10)), count
the number of pairs (a, b) such that both a and b are even.
Code:
30. Write a program to print a dictionary where the keys are numbers
between 1 and 15 (both included) and values are cube of the keys.
Code:
31. Write a program to merge two dictionaries, sort the resultant dictionary and print the
sorted dictionary.
Code:
32. Create a dictionary with the roll number, name and marks of n
students in a class and display the
Code:
33. Repeatedly ask the user to enter a team name and how many games the team has won
and how many they lost. Store this information in a dictionary where the keys are the team
names and the values are lists of the form [wins, losses].
(a) Using the dictionary created above, allow the user to enter a team name and print out
the team's winning percentage.
(b) Using the dictionary, create a list whose entries are the number of wins
of each team. Write a program to check whether the given number is
perfect number or not.
Code:
34. Given the dictionary x = {'k1':'v1', 'k2':'v2', 'k3':'v3'}, create a dictionary with the opposite
mapping, i.e., write a program to create the dictionary as : inverted_x = {'v1': 'k1' , 'v2' :'k2' ,
'v3':'k3'}
Code: