1.
define a function which can generate a dictionary
where the keys are numbers between 1 and 20(both included)
and the values are squre of keys.function should just print
the values only.
2.
with the given list [12,24,35,24,88,120,155,88,120,155]
write a program to print this list after removing all
duplicate values with orginal order reserved
3.
Write a program that accepts a sentence and
calculate the number of upper case letters and lower case
letters.
Suppose the following input is supplied to the program:
'Hello world!'
then the output should be:
UPPER CASE 1
LOWER CASE 9
4.
write a prog to find the integers form a string using list
comperhension
eg:= "devin123"
o/p will be = [1,2,3]
5.
input:- string = "a citizen of ekm fought and won the
elaction"
stop_words = ["in","of","a","and","the"]
output will be:-"citizen ekm fought won elaction"
6.
values = [[1,2,3],[4,5,6],['a','b']]
create a list like [1,4,'a'] from values.
o/p = [1,4,'a'] - using list comprehension
7.
a=[1,2,3,4]
b=[10,1,6]
create a list like [11,2,7,12,3,8,13,4,9,14,5,10] from a and b
using comprehension method.
o/p = [11,2,7,12,3,8,13,4,9,14,5,10]
8.
a = [1,2,3,4]
b = [1,2,3,4]
create a list like [2,4,6,8] from a and b using both
comprehension
and loop method.
# o/p = [2,4,6,8]
9.
num = [1.2,2.3,3.4]
convert to all values to int in num list using inbuilt
function map.
10.
Input:- mat = [[1,2],[3,4],[5,6],[7,8]]
in matrix form,
[[1,2],
[3,4],
[5,6],
[7,8]]
Consider as transpose of a matrix.
Using comperhension.
o/p sould be this format = [[1,3,5,7],
[2,4,6,8]]
11.
Sum of this list [1,2,3,4] using inbuilt function reduce.
12.
Inputs are:-
keys =['name','age']
values = ['devin',26]
Output should be:- {‘name’:’devin’,’age’;’27’}
Using dict comperhension.
13.
Write a program to print multiplication table of a given
number
For example,num = 2 so the output should be
2
4
6
8
10
12
14
16
18
20
14.
Use a loop to display elements from a given list present at
odd index positions
mylist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
15.
Print list in reverse order using a loop
list1 = [10, 20, 30, 40, 50]
16.
Write a program to display only those numbers from a list that
satisfy the following conditions
The number must be divisible by five
If the number is greater than 150, then skip it and move to
the next number
If the number is greater than 500, then stop the loop
numbers = [12, 75, 150, 180, 145, 525, 50]
17.
my_list = ['tool',23,3.4,'bar',55,'toolbar']
find string values from my_list
o/p = ['tool','bar','toolbar']
18.
Print a list like ['x','xx','xxx','xxxx']
19.
Create a Bus object that will inherit all of the variables
and methods of the parent Vehicle class and display it
name, max_speed,,mileage
20.
Create a Bus child class that inherits from the Vehicle class.
The default fare charge of any vehicle is seating capacity *
100.
If Vehicle is Bus instance, we need to add an extra 10% on
full fare as a maintenance charge.
So total fare for bus instance will become the final amount =
total fare + 10% of the total fare.
Note: The bus seating capacity is 50. so the final fare amount
should be 5500.
You need to override the fare() method of a Vehicle class in
Bus class.
# name, mileage , capacity
21.
Write a program to count the total number of digits in a
number using a while loop.
For example, the number is 75869, so the output should be 5.
22.
Write a program which will find all such numbers which are
divisible by 7 but are not a multiple of 5,
between 2000 and 3200 (both included).
The numbers obtained should be printed in a comma-separated
sequence on a single line.
23.
Define a function which can print a dictionary where the keys
are numbers between 1 and 20 (both included) and the values
are square of keys.
Hints:
Use dict[key]=value pattern to put entry into a dictionary.
Use ** operator to get power of a number.
Use range() for loops.
24.
print this pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
25.
Print prime numbers between 25 and 50
start = 25
end = 50