Malpani Caste Programming Guide
Malpani Caste Programming Guide
In [2]:
1 print("siya")
siya
In [3]: 1 print("malpani")
malpani
In [4]: 1 print(12+5)
17
In [2]:
1 #WAP write a number to check whether the number is odd or even store odd elments
2 n=int(input("enter a number"))
3 if n%2==0:
4 print("even")
5 else:
6 print("odd")
enter a number78
even
In [5]:
1 #list
2 A1=[11,23,34,45,56]
3 print(A1[1:3])
[23, 34]
In [3]: 1 #list
2 A1=['blah','lala','tata','byee','heyy']
3 print(A1[-1::-5])
['heyy']
In [4]:
1 #list (in append only add one no)
2 a=[11,23,45,67,'abc']
3 [Link](89)
4 print(a)
In [5]: 1 #list (in extend can add more than one no.)
2 a=[11,23,45,67,'abc']
3 [Link]([90,'xyz',234])
4 print(a)
In [8]: 1 #list
2 a=[11,23,45,67,'abc']
3 [Link](1,96)
4 print(a)
In [11]:
1 #list(tells how many times no. repeated)
2 a=[67,23,45,67,'abc',67,89,67]
3 x=[Link](67)
4 print(x)
23
In [18]: 1 #list(ascending order)(all the inputs should be same like if no. only no. & if al
2 a=[11,45,69,67]
3 [Link]()
4 print(a)
In [20]: 1 #list
2 a=[]
3 print(a)
[]
In [21]: 1 #list
2 a=list()
3 print(a)
[]
In [26]: 1 #list(if the no. u are writing in print is there in ur input then it will print T
2 a=[11,23,45,67,'abc']
3 print(2 in a)
False
In [29]: 1 #list
2 b='siya'
3 b1=list(b)
4 print(b1)
In [19]: 1 #create a list of 6 elements using list and chk no. is odd or even and store even
2 ODD=[]
3 EVEN=[]
4 len=int(input("enter the length of the list:"))
5 for i in range(1,len+1):
6 num=int(input("enter no.:"))
7 if num%2==0:
8 [Link](num)
9 else:
10 [Link](num)
11 print(ODD)
12 print(EVEN)
In [ ]:
1 #create a list of first ten even no. add 1 to each list elment and print the fina
2 a=[]
3 for i in range(1,21):
4 f=int(input("first 21 no."))
5 z=f%2
6 if z==0:
7 [Link](f+1)
8 print("final list",a)
In [21]: 1 #write a program using list to take 10 numbers from user and print the list in re
2 print("HELLO USER")
3 a=[]
4 for i in range(1,11):
5 n=int(input("enter ele:"))
6 [Link](n)
7 print("list before reverse",a)
8 [Link]()
9 print("list after reverse",a)
HELLO USER
enter ele:5
enter ele:6
enter ele:8
enter ele:4
enter ele:2
enter ele:0
enter ele:8
enter ele:6
enter ele:4
enter ele:63
list before reverse [5, 6, 8, 4, 2, 0, 8, 6, 4, 63]
list after reverse [63, 4, 6, 8, 0, 2, 4, 8, 6, 5]
In [1]: 1 #create a list of first ten even numbers add 1 to each list element and print the
2 a=list()
3 for i in range(1,11):
4 if i%2==0:
5 [Link](i+1)
6 print(a)
[3, 5, 7, 9, 11]
In [2]: 1 #create a list of first 20 elements in list A store only even elements in list B
2 A=list()
3 B=list()
4 for i in range (1,21):
5 [Link](i)
6 if i%2==0:
7 [Link](i)
8 print(A)
9 print(B)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
In [7]: 1 #wap to fid no.s that are divisible by 3 and multiple of 5 between 1200 and 2200
2 A=list()
3 for i in range (1200,2201):
4 if i%3==0 and i%5==0:
5 [Link](i)
6 print(A)
[1200, 1215, 1230, 1245, 1260, 1275, 1290, 1305, 1320, 1335, 1350, 1365, 1380, 1
395, 1410, 1425, 1440, 1455, 1470, 1485, 1500, 1515, 1530, 1545, 1560, 1575, 159
0, 1605, 1620, 1635, 1650, 1665, 1680, 1695, 1710, 1725, 1740, 1755, 1770, 1785,
1800, 1815, 1830, 1845, 1860, 1875, 1890, 1905, 1920, 1935, 1950, 1965, 1980, 19
95, 2010, 2025, 2040, 2055, 2070, 2085, 2100, 2115, 2130, 2145, 2160, 2175, 219
0]
In [19]: 1 #wap to delete any second element from the list of given ten elements
2 A=[1,2,3,4,5,6,7,8,9,11]
3 for i in range(1,11):
4 [Link](i)
5 i=i+2
6 print(A)
[1, 3, 4, 5, 6, 7, 8, 9, 11]
[1, 3, 5, 6, 7, 8, 9, 11]
[1, 3, 5, 7, 8, 9, 11]
[1, 3, 5, 7, 9, 11]
[1, 3, 5, 7, 9]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_2976\[Link] in <module>
2 A=[1,2,3,4,5,6,7,8,9,11]
3 for i in range(1,11):
----> 4 [Link](i)
5 i=i+2
6 print(A)
In [20]: 1 #wap to delete any second element from the list of given ten elements
2 A=[1,2,3,4,5,6,7,8,9,10]
3 for i in range(0,11):
4 [Link](i)
5 i=i+3
6 print(A)
[2, 3, 4, 5, 6, 7, 8, 9, 10]
[2, 4, 5, 6, 7, 8, 9, 10]
[2, 4, 6, 7, 8, 9, 10]
[2, 4, 6, 8, 9, 10]
[2, 4, 6, 8, 10]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_2976\[Link] in <module>
2 A=[1,2,3,4,5,6,7,8,9,10]
3 for i in range(0,11):
----> 4 [Link](i)
5 i=i+3
6 print(A)
In [10]:
1 # tb pg 240 q10
2 a=list()
3 age=int(input("enter the age"))
4 if age>60 or age<80 or age==60 or age==80:
5 n=int(input("monthly income"))
6 ai=n*12
7 print("annual income",ai)
8 else:
9 print("thank youu")
10 if ai<300000 or ai==300000:
11 ait=0
12 print("your annual income tax i:",ait)
13 elif ai>300000 or ai<500000:
14 ait=ai*5/100
15 print(" your annual income tax i:",ait)
16 elif ai>500000 and ai<=1000000:
17 ait=ai*20/100
18 print("your annual income tax i:",ait)
19 elif ai>1000000:
20 ait=ai*30/100
21 print(" your annual income tax i:",ait)
In [16]:
1 #wapp last digit for any given no.
2 n=int(input("enter the number"))
3 last_dig=n%10
4 print(last_dig)
In [18]: 1 #wapp first digit of any given no.(works only for 2 digit)
2 n=int(input("enter the number"))
3 first_dig=n//10
4 print(first_dig)
In [20]: 1 #wapp first digit of any given no.(works only for 3 digit)
2 n=int(input("enter the number"))
3 Q=n//10
4 f=Q//10
5 print(f)
In [10]:
1 #wap to reverse a no.(question 3 of lab set 2)
2 a=[]
3 num=int(input("enter a number"))
4 R=num%10
5 Q=num//10
6 R1=Q%10
7 Q1=Q//10
8 print(R,R1,Q1)
enter a number345
5 4 3
In [2]: 1 #wap to chk whether the number input from the user is a palindrome or [Link]
2 num=int(input("enter a number"))
3 temp=num
4 rev= 0
5 while (num > 0):
6 dig=num % 10
7 rev=rev*10+dig
8 num=num//10
9 if(temp==rev):
10 print("the no. is palindrome.")
11 else:
12 print("not a palindrome.")
enter a number767
the no. is palindrome.
In [14]: 1 #wap to display multiplication table of any given no.(q5 of lab set 2)
2 n=int(input("enter a number"))
3 for i in range(0,11):
4 f=i*n
5 print(n,"*",i,"=",f)
enter a number98
98 * 0 = 0
98 * 1 = 98
98 * 2 = 196
98 * 3 = 294
98 * 4 = 392
98 * 5 = 490
98 * 6 = 588
98 * 7 = 686
98 * 8 = 784
98 * 9 = 882
98 * 10 = 980
In [14]:
1 #wap to display the following half pyramid pattern(q6 of lab set 2)
2 #tracing: i=1,range(1,4),j=1,range(1,2)
3 # j=2,range(2,2)X
4 # i=2,range(2,4),j=1,range(1,3)
5 # j=2,range(2,3)
6 # j=3,range(3,3)X
7 # i=3,range(3,4),j=1,range(1,4)
8 # j=2,range(2,4)
9 # j=3,range(3,4)
10 # j=4,range(4,4)X
11 # i=4,range(4,4)X
12
13 n=int(input("no. of rows"))
14 for i in range(0,n+1):
15 for j in range(1,i+1):
16 print("*",end=" ")
17 print()
18
19
no. of rows8
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
In [3]: 1 #wap to display the following half pyramid pattern(q6 of lab set 2)
2 #tracing: i=1,range(1,4),j=1,range(1,2)
3 # j=2,range(2,2)X
4 # i=2,range(2,4),j=1,range(1,3)
5 # j=2,range(2,3)
6 # j=3,range(3,3)X
7 # i=3,range(3,4),j=1,range(1,4)
8 # j=2,range(2,4)
9 # j=3,range(3,4)
10 # j=4,range(4,4)X
11 # i=4,range(4,4)X
12
13 n=int(input("no. of rows"))
14 for i in range(0,n+1):
15 for j in range(1,i+1):
16 print(j,end=" ")
17 print()
18
19
no. of rows7
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
In [13]: 1 #wap to display the following half pyramid pattern(q6 of lab set 2)
2 #tracing: i=1,range(1,4),j=1,range(1,2)
3 # j=2,range(2,2)X
4 # i=2,range(2,4),j=1,range(1,3)
5 # j=2,range(2,3)
6 # j=3,range(3,3)X
7 # i=3,range(3,4),j=1,range(1,4)
8 # j=2,range(2,4)
9 # j=3,range(3,4)
10 # j=4,range(4,4)X
11 # i=4,range(4,4)X
12
13
no. of rows7
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
ABCDEFGHIJKLMNOPQRSTUVWXYZ
no. of rows4
siya
siya siya
siya siya siya
siya siya siya siya
no. of rows6
* * * * * *
* * * * *
* * * *
* * *
* *
*
no. of rows3
1 2 3
1 2
1
no. of rows8
8 8 8 8 8 8 8 8
7 7 7 7 7 7 7
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
In [6]: 1 number=1
2 n=int(input("no. of rows"))
3 for i in range(n,0,-1):
4 for j in range(1,i+1):
5 print(number,end=" ")
6 number+=1
7 print()
8
no. of rows5
1 2 3 4 5
6 7 8 9
10 11 12
13 14
15
In [34]: 1 m=0
2 n=int(input("no. of rows"))
3 for i in range(n,0,-1):
4 m=m+1
5 for j in range(1,i+1):
6 print(m,end=" ")
7 print()
8
no. of rows4
1 1 1 1
2 2 2
3 3
4
no. of rows3
A A A
A A
A
no. of rows5
E E E E E
D D D D
C C C
B B
A
no. of rows3
A B C
A B
A
In [55]:
1
2
no. of rows4
A A A A
A A A
A A
In [19]: 1
In [ ]:
1