You are on page 1of 76

HOW TO

PREPARE FOR
70/70 IN
COMPUTER
SCIENCE (083)
2019-20
Board Exam
DoyPyEdu PLAY WITH PYTHON

Page 1 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

IDENTIFY THE IDENTIFIER/ VARIABLE IN PYHTON USING 12 RULES


Example: Ravi: VALID , #x : INVALID
1. N/10 17. e50isbus 33. Emp*Name 49. _temp
2. 2j 18. INT 34. str 50. 23b9
3. A1b2c3 19. Stu*Name 35. a_b_c 51. Stu#Name
4. Age= 20. Nameofstudent 36. 3ab 52. Stu.Name
5. for 21. Ca_se 37. dobin123 53. int
6. class 22. xyz 38. len 54. Int
7. 1abc 23. void 39. MoNo 55. _1
8. Stu&Name 24. _my 40. #ax 56. _
9. Name_of_student 25. Float 41. ax# 57. _ _A_ _b
10. Yk.sd 26. float 42. ax 58. _ _ _ _ _b
11. bool 27. student_name 43. Stubent_Name 59. true
12. Stu_Name 28. s.name 44. pow 60. True
13. a_b_c123 29. ifelse 45. move_na 61. false
14. 1Roll_NO 30. break 46. a_123 62. False
15. 1a2b3c 31. Stu_name 47. e50isbus 63. length
16. My.nameis.sanju 32. @abc 48. INT 64. Length

WORKSHEET WITH OUTPUT using : %, format


Sample 1:
a=19.1687
print(a) # 19.1687
print("%d"%a) #19
print("%f"%a) #19.168700
print("%.3f"%a) #19.169
print("%.2f"%a) #19.17
print("%.1f"%a) #19.2
Sample 2:
a,b,c=5,6,19
print(a,b,c) #5619
print(a,", ",b,", ",c) #5,6,19
print("%d,%d,%d "%(a,b,c)) #5,6,19
print("%d,%f,%.3f "%(a,b,c)) #5,6.000000,19.000
Sample 3:
x=17.12876 print("%f,%.3f ,%.4f,%.2f"%(x,x,x,x)) #17.128760, 17.129, 17.1288, 17.13
a,b,c=5,6,19
print("the sum of {} and {} is {} ".format(a,b,c)) # the sum of 5 and 6 is 19
print("{0} , {1}, {2} ".format(a,b,c)) #5,6,19
print("{2} , {0} ,{1} ".format(a,b,c)) #19,5,6
print("{v1} , {v2} ".format(v1=a,v2=b)) #5,6 by ID
print("{0},{2},{1} ".format(a,b,c)) # 5 19 6
Sample 4:
a,b,c=5,6,19
print("{0},{1},{2} ".format(a,b,c)) #5,6,19
print("{1},{2},{2} ".format(a,b,c)) #6,19,19
print("{2},{1},{0} ".format(a,b,c)) #19,6,5
print("{1},{1},{1} ".format(a,b,c)) #6,6,6
print("{v1} , {v2}, {v3} ".format(v1=a,v2=b,v3=c)) #5,6,19
print("

Page 2 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
{v2} , {v2}, {v3} ".format(v1=a,v2=b,v3=c)) #6,6,19
print("{v3} , {v2}, {v3} ".format(v1=a,v2=b,v3=c)) #19,6,19
print("{v1} , {v2}, {v1} ".format(v1=a,v2=b,v3=c)) #5,6,5
Sample 5:
a,b,c="Python","JAVA","C++"
print(a) # Output:Python
print(a*3) # Output:PythonPythonPython
print("%s"%a) # Output:Python
print (" %s , %s , %s" % (a,b,c)) #Python ,JAVA ,C++
print("{},{},{}".format(a,b,c)) # Output:Python,JAVA,C++
print("{1},{2},{0}".format(a,b,c)) # Output:JAVA,C++,Python
print("{2},{0},{1}".format(a,b,c)) # Output:C++,Python,JAVA
print('Hello {lang1}, {lang2}'.format(lang1 = 'C++', lang2= 'JAVA')) # Output:Hello C++, JAVA
print('Hello {lang2}, {lang1}'.format(lang1 = 'C++', lang2= 'JAVA')) # Output:Hello JAVA, C++

Unsolved Assignment
Find Output:
1) ch=input(“Enter Your Choice: 3) in=int(input(“Enter in: “)) a=a*4
“) col=int(input(“Enter col: “)) else:
m=3 if in==5: a=a+a
if x==‟a‟ : m*=2 col=col+1 print(a)
elif x==‟c‟ : m/=2 elif in==10: Result after execution if:
elif x==‟d‟: m+=3 col=col*2 a 2 7 9 7 13
else: m*=3 else: Ans
print (m) col=col+4 5) a=int(input(“Enter Value of a:
Result after execution if: print(col) “))
x „a‟ „c‟ „g‟ „d‟ Result after execution if: b=int(input(“Enter Value of b: “))
m in 6 5 10 9 if (a<b or a>5)>10:
2) ch=input(“Enter Your Choice: col 16 4 7 2 print(a)
“) col else: print(b)
if ch= = „a‟ : print(“I”) 4) a=int(input(“Enter Value of a: Result after execution if:
elif ch= = „b‟ or ch== „d‟: ”)) a 4 12 10 5
print (“II”) if a==1: b 6 3 7 9
else: print( “III”) a=a*a Ans
Result after execution if: elif a==3 or a==4 or a==5:
6) x=int(input(“Enter Value of x :
x „d‟ „h‟ „g‟ „a‟ a=a*3 “))
Ans elif a==6 or a==7 or a==8: y=int(input(“Enter Value of y : “))
Page 3 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
if x>5: else: print (x) Ans
if y>5: x 4 12 10 5
print(y) y 6 3 7 9
Condition (if else) Output Assignment 1
Que. 1 . x=x+3 y=4
x=2 y=x+4 if x>=y:
y=1 print("x= ",x,", y= ",y) if x>y:
if x>12: ----------------------- x=x*3
x=x*2 Que. 7 . print("x= ",x,", y= ",y)
y=x+10 x=12 -----------------------
print("x= ",x,", y= ",y) y=4 Que. 12 .
----------------------- if x>y: x=4
Que. 2 . x=x*3 y=4
x=12 y=x*4 if x>y:
y=11 else: if x<y:
if x>=12: x=x+3 x=y*3
x=x*2 y=x+4 print("x= ",x,", y= ",y)
y=x+10 print("x= ",x,", y= ",y) -----------------------
print("x= ",x,", y= ",y) ----------------------- Que. 13 .
----------------------- Que. 8 . x=4
Que. 3 . x=2 y=4
x=11 y=4 if x>y:
y=11 if x!=y: if x>y:
if x<12: x=x-3 x=y*3
x=x+2 y=x*4 print("x= ",x,", y= ",y)
y=x*3 else: -----------------------
print("x= ",x,", y= ",y) x=x-3 Que. 14 .
----------------------- y=x+4 x=4
Que. 4 . print("x= ",x,", y= ",y) y=4
x=11 ----------------------- if x<y:
y=11 Que. 9 . if x>y:
if x!=y: x=2 x=y*3
x=x+3 y=4 print("x= ",x,", y= ",y)
y=x+4 if x!=y: -----------------------
print("x= ",x,", y= ",y) if x>y: Que. 15 .
----------------------- x=x-3 x=4
Que. 5 . else: y=4
x=2 y=x+4 if x==y:
y=4 print("x= ",x,", y= ",y) if x>y:
if x==y: ----------------------- x=y*3
x=x*3 Que. 10 . print("x= ",x,", y= ",y)
y=x*4 x=2 -----------------------
print("x= ",x,", y= ",y) y=4 Que. 16 .
----------------------- if x>=y: x=4
Que. 6 . if x>y: y=4
x=2 x=x*3 if x==y:
y=4 else: y=x+9 if x>y:
if x>y: print("x= ",x,", y= ",y) x=y*3
x=x*3 ----------------------- y+=6
y=x*4 Que. 11 . print("x= ",x,", y= ",y)
else: x=2 -----------------------
Output:
ANS 1 : x= 2 , y= 1 ------------------------------
Page 4 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON

ANS 2 : ANS 7 : ANS 12 :


x= 24 , y= 34 x= 36 , y= 144 x= 4 , y= 4
------------------------------ ------------------------------ ------------------------------
ANS 3 : ANS 8 : ANS 13 :
x= 13 , y= 39 x= -1 , y= -4 x= 4 , y= 4
------------------------------ ------------------------------ ------------------------------
ANS 4 : ANS 9 : ANS 14 :
x= 11 , y= 11 x= 2 , y= 6 x= 4 , y= 4
------------------------------ ------------------------------ ------------------------------
ANS 5 : ANS 10 : ANS 15 :
x= 2 , y= 4 x= 2 , y= 4 x= 4 , y= 4
------------------------------ ------------------------------ ------------------------------
ANS 6 : ANS 11 : ANS 16 :
x= 5 , y= 9 x= 2 , y= 4 x= 4 , y= 10
------------------------------ ------------------------------ ------------------------------

Page 5 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

New Python Worksheet


Loop Output Assignment 1
Que. 1 . print(i,end="")
x="DOTPYEDU" print()
for i in x: -----------------------
print(i, end="") Que. 7 .
----------------------- x="Education"
Que. 2 . for i in range(len(x)):
x="DOTPYEDU" for i in range(len(x)-1):
for i in x: print(x[i],end="")
for i in x: print()
print(i, end="") -----------------------
print("*") Que. 8 .
----------------------- x="EducAtiOn"
Que. 3 . v=[]
x="DOTPYEDU" l=['a','e','i','o','u',]
for i in x: for i in range(len(x)):
for i in x: if x[i] in l:
print(i,end="") v.append(x[i])
print() print(v)
----------------------- -----------------------
Que. 5 . Que. 9 .
x="DOTPYEDU" x="EducAtiOn"
for i in range(len(x)): l=['a','e','i','o','u']
for i in x: v=[]
print(i,end="") for i in range(len(x)):
print() if x[i].lower() in l:
Que. 6 . v.append(x[i])
x="DOTPYEDU" print(v)
for i in range(len(x)): -----------------------
for i in range(len(x)-1): Que. 10 .
Page 6 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
x="Education For Everyone" -----------------------
l=['a','e','i','o','u','A','E','I','O','U'] Que. 15 .
v=[] x="DOTPYEDU"
for i in range(len(x)): l=['a','e','i','o','u','A','E','I','O','U']
if x[i] in l: for i in x:
v.append(x[i]) if i in l:
print(v) print(i.lower(),end="")
----------------------- else:
Que. 11 . print(i.upper(),end="")
x="Education For Everyone" -----------------------
l=['a','e','i','o','u','A','E','I','O','U'] Que. 16 .
v=[] x="DOTPYEDU"
for i in range(len(x)): l=['a','e','i','o','u','A','E','I','O','U']
if x[i] in l: newlist=[]
v.append(x[i]) for i in x:
print(v) if i in l:
----------------------- newlist.append(i.lower())
Que. 12 . else:
x="DOTPYEDU" newlist.append(i.upper())
for i in x: print(newlist)
print(x,end=" $ ") -----------------------
----------------------- Que. 17.
Que. 13 . x="DOTPYEDU"
x="DOTPYEDU" l=['a','e','i','o','u','A','E','I','O','U']
for i in x: newlist=[]
print(x.lower(),end=" # ") for i in x:
----------------------- if i in l:
Que. 14 . newlist.append(i.lower())
x="DOTPYEDU" else:
l=['a','e','i','o','u','A','E','I','O','U'] newlist.append(i.upper())
for i in x: print(newlist)
if i in l: old=""
print(x.lower(),end="") old=old.join(newlist)
else: print(old)
print(x.upper(),end="") -----------------------
print() """
OUTPUT:
ANS 1 : DOTPYEDU 0123456 Educatio
DOTPYEDU DOTPYEDU 0123456 ---------------------
----------------------- DOTPYEDU 0123456 ANS 8 :
ANS 2 : DOTPYEDU 0123456 ['u', 'i']
DOTPYEDU* DOTPYEDU 0123456 ----------------------
DOTPYEDU* ---------------------- 0123456 ANS 9 :
DOTPYEDU* ANS 5 : 0123456 ['E', 'u', 'A', 'i', 'O']
DOTPYEDU* DOTPYEDU -------------------- -----------------------
DOTPYEDU* DOTPYEDU ANS 7 : ANS 10 :
DOTPYEDU* DOTPYEDU Educatio ['E', 'u', 'a', 'i', 'o',
DOTPYEDU* DOTPYEDU Educatio 'o', 'E', 'e', 'o', 'e']
DOTPYEDU* DOTPYEDU Educatio -------------------
----------------------- DOTPYEDU Educatio ANS 11 :
ANS 3 : DOTPYEDU Educatio ['E', 'u', 'a', 'i', 'o',
DOTPYEDU DOTPYEDU Educatio 'o', 'E', 'e', 'o', 'e']
DOTPYEDU ANS 6 : Educatio --------------------
DOTPYEDU 0123456 Educatio ANS 12 :
Page 7 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
DOTPYEDU $ dotpyedu # dotpyedu ANS 16 :
DOTPYEDU $ dotpyedu # DOTPYEDU ['D', 'o', 'T', 'P', 'Y',
DOTPYEDU $ dotpyedu # DOTPYEDU 'e', 'D', 'u']
DOTPYEDU $ dotpyedu # DOTPYEDU ------------------
DOTPYEDU $ dotpyedu # dotpyedu Q 17:
DOTPYEDU $ dotpyedu # DOTPYEDU ['D', 'o', 'T', 'P', 'Y',
DOTPYEDU $ dotpyedu # dotpyedu 'e', 'D', 'u']
DOTPYEDU $ dotpyedu # -------------------- DoTPYeDu
--------------------- ------------------ ANS 15 : ------------------
ANS 13 : ANS 14 : DoTPYeDu
DOTPYEDU ---------------------

Page 8 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

Page 9 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

Unsolved problems
1. Write PYTHON Code for this :

2. Write a program to print the following from a string :


1) The string repeated 10 times
2) The string backwards
3) The string in all caps
4) The first character of the string
5) The first three characters of the string
6) The last three characters of the string
7) The total number of characters in the string
8) The string with its first and last characters removed
9) The string with every „a‟ replaced with an „e‟
10) The string with every letter replaced by a space
3. Write a program convert given string into:
a. Capitalize Case
b. Togle Case
c. Sentence Case
4. WAP to count in given message.
a. Upper Case.
b. Lower Case
c. Words,
d. Space
e. Digits
f. Special Characters 5. WAP to count words start with Capital letters
a. Small letters
b. Digits
c. Special character in given message.
1. WAP to count words end with
a) Capital letters
b) Small letters
c) Digits
2. Special character in given message. WAP to replace every space with a hyphen(#) in
string .
3. WAP to remove all space present in in string .
4. WAP that check the characteror word present in a string or not.
5. Write a program to check givin string is palindrome or not.

Page 10 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

6. WAP to take a string and display longest/ smallest word present in it.
7. WAP to take 10 names and display those name start and end with same character.
8. WAP to take 10 names and display that name are palindrome.
9. WAP to take 10 names and display those name length is 3 only.
10. WAP to take 10 names and display all name in pig Latin format.
11. WAP to take 10 names and arrange all names in length in ascending order.
12. WAP to take 10 names and display number of consonants and vowel of each name.
13. WAP to take 10 names and display all names in reverse.
14. WAP to accept a sentence and print the Palindrome words
New Python Worksheet
String Output Assignment 1
Que. 1 . str="DOTPYEDU" str="DOTPYEDU" print(str[i:])
x="DOT" for i in range(len(str)): for i in range(len(str)): -----------------------
y="PY" print(str) print(str[i*-1::]) Que. 20.
z="EDU" ----------------------- ----------------------- str="DOTPYEDU"
r=x+y+z Que. 8. Que. 14. for i in range(len(str)):
print(r) str="DOTPYEDU" str="DOTPYEDU" print(str[i:i+1])
----------------------- for i in range(len(str)): for i in range(len(str)): -----------------------
Que. 2 . print(str*i) print(str[i*-1::]) Que. 21.
x="DOT" ----------------------- ----------------------- str="DOTPYEDU"
y="PY" Que. 9. Que. 15. for i in range(len(str)):
z="EDU" str="DOTPYEDU" str="DOTPYEDU" print(str[i::i+1])
r=x*3+y*1+z*2 for i in range(len(str)): for i in range(len(str)): -----------------------
print(r) print(str[:]) print(str[i*-1::-2]) Que. 22.
----------------------- ----------------------- ----------------------- str="DOTPYEDU"
Que. 3 . Que. 9. Que. 16. for i in range(len(str)):
str="DOTPYEDU" str="DOTPYEDU" str="DOTPYEDU" print(str[i:len(str)])
r=str*3 for i in range(len(str)): for i in range(len(str)): -----------------------
print(r) print(str[::]) print(str[i*-1::2]) Que. 23.
----------------------- ----------------------- ----------------------- str="DOTPYEDU"
Que. 4 . Que. 10. Que. 17. for i in range(len(str)):
str="DOTPYEDU" str="DOTPYEDU" str="DOTPYEDU" print(str[i:len(str)-
r=str*3 for i in range(len(str)): for i in range(len(str)): i])
print(r) print(str[::2]) if i%2==0: -----------------------
----------------------- ----------------------- print(str[i:]) Que. 24.
Que. 5. Que. 11. ----------------------- str="DOTPYEDU"
str="DOTPYEDU" str="DOTPYEDU" Que. 18. for i in range(len(str)):
for i in str: for i in range(len(str)): str="DOTPYEDU" print(str[i:len(str)-
print(str) print(str[i::]) for i in range(len(str)): i%2])
----------------------- ----------------------- if i%3==0: -----------------------
Que. 6. Que. 12. print(str[i:]) Que. 25.
str="DOTPYEDU" str="DOTPYEDU" ----------------------- str="DOTPYEDU"
for i in str: for i in range(len(str)): Que. 19. for i in range(len(str)):
print(i) print(str[i::i+1]) str="DOTPYEDU" print(str[i:len(str)-
----------------------- ----------------------- for i in range(len(str)): i%2])
Que. 7. Que. 13. if i%3!=0: -----------------------

Page 11 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

OUTPUT:
ANS 1 : DOTPYEDUDOTPYEDUDOTPYEDUDOT E
DOTPYEDU PYEDUDOTPYEDUDOTPYEDU D
------------------------------ DOTPYEDUDOTPYEDUDOTPYEDUDOT U
ANS 2 : PYEDUDOTPYEDUDOTPYEDUDOTPYE ------------------------------
DOTDOTDOTPYEDUEDU DU ANS 13:
------------------------------ ------------------------------ DOTPYEDU
ANS 3 : ANS 9: U
DOTPYEDUDOTPYEDUDOTPYEDU DOTPYEDU DU
------------------------------ DOTPYEDU EDU
ANS 4 : DOTPYEDU YEDU
DOTPYEDUDOTPYEDUDOTPYEDU DOTPYEDU PYEDU
------------------------------ DOTPYEDU TPYEDU
ANS 5: DOTPYEDU OTPYEDU
DOTPYEDU DOTPYEDU ------------------------------
DOTPYEDU DOTPYEDU ANS 14:
DOTPYEDU ------------------------------ DOTPYEDU
DOTPYEDU ANS 9: U
DOTPYEDU DOTPYEDU DU
DOTPYEDU DOTPYEDU EDU
DOTPYEDU DOTPYEDU YEDU
DOTPYEDU DOTPYEDU PYEDU
------------------------------ DOTPYEDU TPYEDU
ANS 6: DOTPYEDU OTPYEDU
D DOTPYEDU ------------------------------
O DOTPYEDU ANS 15:
T ------------------------------ D
P ANS 10: UEPO
Y DTYD DYTD
E DTYD EPO
D DTYD YTD
U DTYD PO
------------------------------ DTYD TD
ANS 7: DTYD O
DOTPYEDU DTYD ------------------------------
DOTPYEDU DTYD ANS 16:
DOTPYEDU ------------------------------ DTYD
DOTPYEDU ANS 11: U
DOTPYEDU DOTPYEDU D
DOTPYEDU OTPYEDU EU
DOTPYEDU TPYEDU YD
DOTPYEDU PYEDU PEU
------------------------------ YEDU TYD
ANS 8: EDU OPEU
DU ------------------------------
DOTPYEDU U ANS 17:
DOTPYEDUDOTPYEDU ------------------------------ DOTPYEDU
DOTPYEDUDOTPYEDUDOTPYEDU ANS 12: TPYEDU
DOTPYEDUDOTPYEDUDOTPYEDUDOT DOTPYEDU YEDU
PYEDU OPEU DU
DOTPYEDUDOTPYEDUDOTPYEDUDOT TE ------------------------------
PYEDUDOTPYEDU PU ANS 18:
Y DOTPYEDU

Page 12 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

PYEDU OPEU PY
DU TE ------------------------------
------------------------------ PU ANS 24:
ANS 19: Y DOTPYEDU
OTPYEDU E OTPYED
TPYEDU D TPYEDU
YEDU U PYED
EDU ------------------------------ YEDU
U ANS 22: ED
------------------------------ DOTPYEDU DU
ANS 20: OTPYEDU ------------------------------
D TPYEDU ANS 25:
O PYEDU DOTPYEDU
T YEDU OTPYED
P EDU TPYEDU
Y DU PYED
E U YEDU
D ------------------------------ ED
U ANS 23: DU
------------------------------ DOTPYEDU ------------------------------
ANS 21: OTPYED
DOTPYEDU TPYE
String Output Assignment 2
Que. 1 . if i%2!=0: print(r)
s="CBSE Exam 2019-2020" r+=s[i].upper() ***************
print(s) else: Que. 6 .
r="" r+=s[i].lower() s="Cbse Exam 2019-2020"
size=len(s) print(r) print(s)
for i in range(size): *************** r=""
if i%2==0: Que. 4 . for i in s:
r+=s[i].upper() s="Cbse Exam 2019-2020" if i.isupper():
else: print(s) r+=i.lower()
r+=s[i] r="" elif i.islower():
print(r) size=len(s) r+=i.upper()
*************** for i in range(size): else:
Que. 2 . if i%3==0: r=r+i
s="Cbse Exam 2019-2020" r+=s[i].upper() print(r)
print(s) else: ***************
r="" r+=s[i].lower() Que. 7 .
size=len(s) print(r) s="Cbse Exam 2019-2020"
for i in range(size): *************** print(s)
if i%2==0: Que. 5 . r=""
r+=s[i].upper() s="Cbse Exam 2019-2020" for i in s:
else: print(s) if i.isupper()== False:
r+=s[i].lower() r="" r+=i.lower()
print(r) size=len(s) elif i.islower()== False:
*************** for i in range(size): r+=i.upper()
Que. 3 . if i%3==0: else:
s="Cbse Exam 2019-2020" r+=s[i].upper() r=r+i
print(s) elif i%2==0: print(r)
r="" r+=s[i].lower() ***************
size=len(s) else: Que. 8 .
for i in range(size): r=r+s[i] s="Cbse Exam 2019-2020"

Page 13 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

print(s) r=r+i elif i.islower():


r="" print(r) if s.find(i)%3==0:
for i in s: *************** r+=i.upper()
if i.isupper()== True: Que. 12 . if s.find(i)%3!=0:
r+=i.lower() s="Cbse Exam 2019-2020" r+=i.upper()
elif i.islower()== False: print(s) elif i.isdigit():
r+=i.upper() r="" p=int(i)
else: for i in s: if p%2==0:
r=r+i if i.isupper(): p=0
print(r) r+=(chr(ord(i)-3)).upper() else:
*************** elif i.islower(): p=1
Que. 9 . r+=(chr(ord(i)-1)).upper() r+=str(p)
s="Cbse Exam 2019-2020" elif i.isdigit(): else:
print(s) p=int(i) r=r+i
r="" if p>8: print(r)
for i in s: p-=2 ***************
if i.isupper(): else: Que. 15.
r+=i.lower() p+=1 s="Cbse Exam 2019-2020"
elif i.islower(): r+=str(p) l=['a','e','i','o','u','A','E','I','O','U']
r+=i.upper() else: print(s)
elif i.isdigit(): r=r+i r=""
r+=str(int(i)+1) print(r) for i in s:
else: *************** p=s.find(i)
r=r+i Que. 13 . if i in l:
print(r) s="Cbse Exam 2019-2020" r+=str(l[p: ])
*************** print(s) elif i in l:
Que. 10 . r="" r+=str(l[p: ])
s="Cbse Exam 2019-2020" for i in s: elif i.isdigit():
print(s) if i.isupper(): r+=str(l[0])
r="" r+=(chr(ord(i)+1)).upper() else:
for i in s: elif i.islower(): r=r+i
if i.isupper(): r+=(chr(ord(i)+1)).upper() print(r)
r+=(chr(ord(i)+1)).upper() elif i.isdigit(): ***************
elif i.islower(): p=int(i) Que. 16.
r+=(chr(ord(i)+2)).upper() if p%2==0: s="Cbse Exam 2019-2020"
elif i.isdigit(): p=0 l=['a','e','i','o','u','A','E','I','O','U']
r+=str(int(i)+1) else: print(s)
else: p=1 r=""
r=r+i r+=str(p) x=0
print(r) else: while x <len(s):
*************** r=r+i i=s[x]
Que. 11 . print(r) p=s.find(i)
s="Cbse Exam 2019-2020" *************** if i in l:
print(s) Que. 14 . r+=str(l[p: ])
r="" s="Cbse Exam 2019-2020" elif i in l:
for i in s: print(s) r+=str(l[p: ])
if i.isupper(): r="" elif i.isdigit():
r+=(chr(ord(i)-1)).upper() for i in s: r+=str(l[0])
elif i.islower(): if i.isupper(): else:
r+=(chr(ord(i)-2)).upper() if s.find(i)%2==0: r=r+i
elif i.isdigit(): r+=i.upper() x+=1
r+=str(int(i)+1) if s.find(i)%2!=0: print(r)
else: r+=i.upper() ***************

Page 14 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

Que. 17. print(l) Que. 19.


s="Cbse Exam 2019-2020" print(len(l)) s="Cbse Exam 2019-2020"
l=s.split() *************** l=s.split('a')
print(l) Que. 19. for i in l:
print(len(l)) s="Cbse Exam 2019-2020" if len(i)>5:
*************** l=s.split('a')
Que. 18. for i in l: print(i," : ",len(i))
s="Cbse Exam 2019-2020" print(i," : ",len(i)) ***************
l=s.split('a') ***************
Output:
ANS 1 : Cbse Exam 2019-2020 Cbs['o', 'u', 'A', 'E', 'I', 'O', 'U'] ['A',
CBSE Exam 2019-2020 cbse exam 2019-2020 'E', 'I', 'O', 'U']x['I', 'O', 'U']m aaaa-
CBSE EXaM 2019-2020 ****************** aaaa
****************** ANS 9 : ******************
ANS 2 : Cbse Exam 2019-2020 ANS 16:
Cbse Exam 2019-2020 cBSE eXAM 31210-3131 Cbse Exam 2019-2020
CbSe eXaM 2019-2020 ****************** Cbs['o', 'u', 'A', 'E', 'I', 'O', 'U'] ['A',
****************** ANS 10 : 'E', 'I', 'O', 'U']x['I', 'O', 'U']m aaaa-
ANS 3 : Cbse Exam 2019-2020 aaaa
Cbse Exam 2019-2020 DDUG FZCO 31210-3131 ******************
cBsE ExAm 2019-2020 ****************** ANS 17:
****************** ANS 11 : ['Cbse', 'Exam', '2019-2020']
ANS 4 : Cbse Exam 2019-2020 3
Cbse Exam 2019-2020 B`ANSC DV_K 31210-3131 ******************
CbsE eXam 2019-2020 ****************** ANS 18:
****************** ANS 12 : ['Cbse Ex', 'm 2019-2020']
ANS 5 : Cbse Exam 2019-2020 2
Cbse Exam 2019-2020 @ARD BW`L 3127-3131 ******************
CbsE EXam 2019-2020 ****************** ANS 19:
****************** ANS 13 : Cbse Ex : 7
ANS 6 : Cbse Exam 2019-2020 m 2019-2020 : 11
Cbse Exam 2019-2020 DCTF FYBN 0011-0000 ******************
cBSE eXAM 2019-2020 ****************** ANS 19:
****************** ANS 14 : Cbse Ex : 7
ANS 7 : Cbse Exam 2019-2020 m 2019-2020 : 11
Cbse Exam 2019-2020 CBSE EXAM 0011-0000 ******************
Cbse Exam 2019-2020 ******************
****************** ANS 15:
ANS 8 : Cbse Exam 2019-2020

Page 15 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

String Output Assignment 3


print("Q 01. ") Msg+=MyText[cnt].lower() if (x%2==0):
T= "Mind@work!" elif MyText[cnt]=='A' or r+=s[x-1].lower()
R="" MyText[cnt]=='a': else:
l=len(T) Msg+=ch; r+=chr(ord(s[x])-2)
print("Original : ",T) else: print(" Final : ",r)
for i in range(l): if(cnt%2==0): ***************
if T[i].isalpha()==False: Msg+=MyText[cnt].upper() print("Q 08.")
R+='*'; else: poet= "SakESpHerE" ;
elif T[i].isupper()==True: Msg+=MyText[cnt-1] l=len(poet)
R+=chr(ord(T[i])+1) print("Final :",Msg) r=""
else: *************** print("Original : ",poet)
R+= T[i+1] print("Q 05.") for i in range(l):
print("Final : ",R) Message="ArabSagar"; if poet[i].islower():
*************** SMS=[ i for i in Message] r+=poet[i-1]
print("Q 02.") print("Original : ",Message) elif poet[i].isupper():
Mystring= "what@OUTPUT!" l=len(SMS) if poet[i]=='S':
l=len(Mystring) L=l r+='X';
R="" R="" elif(poet[i]=='E'):
print("Original : ",Mystring) for C in range(0, int(l/2)): r+=poet[i-1].upper()
for i in range(l): if SMS[C]=='A' or SMS[C]=='E': else:
if Mystring[i].isalpha()==False: SMS[C]='#' r+=chr(ord(poet[i])-1)
R+="*"; else: print(" Final : ",r)
elif Mystring[i].isupper(): Temp=SMS[C] ***************
R+=chr(ord(Mystring[i])+1) SMS[C]=SMS[L-C-1] print("Q 09.")
else: SMS[L-C-1]=Temp poet= "SakESpHerE" ;
R+=Mystring[i+1] Message =''.join(SMS) l=len(poet)
print("Final :",R) print("Final :",Message) r=""
*************** *************** print("Original : ",poet)
print("Q 03. ") print("Q 06.") for i in range(l):
SMS="rEPorTmE"; s= "a ProFile" if poet[i].islower():
l=len(SMS) print("Original : ",s) r+=poet[i-1]
R="" l=len(s) elif poet[i].isupper():
print("Original : ",SMS) r="" if poet[i]=='S':
N=2 for x in range(l): r+='X';
for c in range(l): if s[x].islower(): elif(poet[i]=='E'):
if c%2==0: r+=s[x].upper() r+=poet[i-1].upper()
R+= chr(ord(SMS[c])+N) elif s[x].isupper(): else:
elif SMS[c].isupper()==True: if (x%2!=0): r+=chr(ord(poet[i])-1)
R+=SMS[c].lower() r+=s[x-1].lower() print(" Final : ",r)
else: else: ***************
R+=chr(ord(SMS[c])-N) r+=chr(ord(s[x])-1) print("Q 10.")
print("Final :",R) print(" Final : ",r) poet= "SakESpHerE" ;
*************** *************** l=len(poet)
print("Q 04. ") print("Q 07.") r=""
MyText="ApEACeDriVE" s = "admiNStrAtiOn" print("Original : ",poet)
ch="@" print("Original : ",s) for i in range(l):
l=len(MyText) l=len(s) if poet[i].islower():
Msg="" r="" r+=poet[i-2]
print("\n Original : ",MyText) for x in range(l): elif poet[i].isupper():
for cnt in range (l): if s[x].islower(): if poet[i]=='S':
if MyText[cnt]>='B' and r+=s[x].upper() r+='X';
MyText[cnt]<='G': elif s[x].isupper(): elif(poet[i]=='E'):

Page 16 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

r+=poet[i-2].upper() for K in range(l): ***************


else: if ( K % 2 == 0): print("Q 18.")
r+=chr(ord(poet[i])-2) r+=chr(ord(Note[K])+NUM-1) N="ComPUteR";
print(" Final : ",r) elif Note[K].islower(): l=len(N)
*************** r+=Note[K].upper() r=""
print("Q 11.") else: print("Original : ",N)
T="SaVE EArtH"; r+=chr(ord(Note[K])+NUM) for x in range(l):
l=len(T) print("Final : ",r) if N[x].islower():
r="" *************** r+=N[x].upper()
print("Original : ",T) print("Q 15.") else:
for i in range(0,l,2): Note = "Butterfly"; if N[x].isupper():
if (T[i]=='A' or T[i]=='E'): NUM=2 if x%2==0:
r+='#'; l=len(Note ) r+=N[x].lower()
elif T[i].islower(): r="" else:
r+=T[i].upper(); print("Original : ",Note ) r+=N[x-1]
else: for K in range(l): print("Final : ",r)
r+='@' if ( K % 2 != 0): ***************
print("Final : ",r) r+=chr(ord(Note[K])+NUM-1) print("Q 19.")
*************** elif Note[K].islower(): N="ComPUteR";
print("Q 12.") r+=Note[K].upper() l=len(N)
T="SaVE EArtH"; else: r=""
l=len(T) r+=chr(ord(Note[K])+NUM) print("Original : ",N)
r="" print("Final : ",r) for x in range(l):
print("Original : ",T) *************** if N[x].islower():
for i in range(0,l): print("Q 16") r+=N[x].upper()
if (T[i]=='A' or T[i]=='E'): Note = "Butterfly"; elif N[x].isupper():
r+='#'; NUM=2 if x%2!=0:
elif T[i].islower(): l=len(Note ) r+=N[x].lower()
r+=T[i].upper(); r="" else:
else: print("Original : ",Note ) r+=N[x-2]
r+='@' for K in range(l): print("Final : ",r)
print("Final : ",r) if ( K % 2 != 0): ***************
*************** r+=chr(ord(Note[K])-NUM) print("Q 20.")
print("Q 13.") elif Note[K].islower(): name= "teAmIndia"
T="SaVE EArtH"; r+=Note[K].upper() l=len(name)
l=len(T) else: r=""
r="" r+=chr(ord(Note[K])+NUM) print("Original : ",name)
print("Original : ",T) print("Final : ",r) for i in range(0,l,2):
for i in range(l): *************** if name[i].islower():
if (T[i]=='A' or T[i]=='H'): print("Q 17.") r+=name[i].upper()
r+='@'; N="ComPUteR"; else:
elif T[i].isupper(): l=len(N) r+=name[i].lower()
r+=T[i].lower(); r="" print("Final : ",r)
else: print("Original : ",N) ***************
r+='#' for x in range(l): print("Q 21.")
print("Final : ",r) if N[x].islower(): name= "teAmIndia"
*************** r+=N[x].upper() l=len(name)
print("Q 14.") elif N[x].isupper(): r=""
Note = "Butterfly"; if x%2==0: print("Original : ",name)
NUM=2 r+=N[x].lower() for i in range(0,l,3):
l=len(Note ) else: if name[i].islower():
r="" r+=N[x-1] r+=name[i].upper()
print("Original : ",Note ) print("Final : ",r) else:

Page 17 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

r+=name[i].lower() *************** name= "ThE bESt mEN wIN";


print("Final : ",r) print("Q 23.") l=len(name)
*************** name= "ThE bESt mEN wIN"; r=""
print("Q 22.") l=len(name) print("Original : ",name)
name= "ThE bESt mEN wIN"; r="" for i in range(l):
l=len(name) print("Original : ",name) if name[i].islower():
r="" for i in range(l): r+= name[i].upper()
print("Original : ",name) if name[i].islower(): else:
for i in range(l): r+= name[i].upper() if name[i].isupper():
if name[i].islower(): elif name[i].isupper(): if i%2==0:
r+= name[i].upper() if i%2==0: r+=chr(ord(name[i])-1)
elif name[i].isupper(): r+=chr(ord(name[i])-1) else:
if i%2==0: else: r+= name[i - 1].lower();
r+=chr(ord(name[i])-1) r+= name[i - 1].lower(); print("Final : ",r)
else: print("Final : ",r)
r+= name[i - 1].lower(); *************** ***************
print("Final : ",r) print("Q 24.")
Output:
Q 01. Q 09. Q 17.
Original : Mind@work! Original : SakESpHerE Original : ComPUteR
Final : Nnd@*ork!* Final : XSaXSHe Final : cOMuTE
************************* ************************ *********************
Q 02. Q 10. Q 18.
Original : what@OUTPUT! Original : SakESpHerE Original : ComPUteR
Final : hat@*PVUQVU* Final : XESXEpH Final : cOMmuTEe
********************** ******************** ************************
Q 03. Q 11. Q 19.
Original : rEPorTmE Original : SaVE EArtH Original : ComPUteR
Final : teRmttoe Final : @@@#T Final : eOMpmTEr
*********************** ************************** **********************
Q 04. Q 12. Q 20.
Original : ApEACeDriVE Original : SaVE EArtH Original : teAmIndia
Final : @Ae@cCdDIie Final : @A@#@##RT@ Final : TaiDA
************************ *********************** ***********************
Q 05. Q 13. Q 21.
Original : ArabSagar Original : SaVE EArtH Original : teAmIndia
Final : aab#raSgr Final : s#ve#e@##@ Final : TMD
************************ *********************** *************************
Q 06. Q 14. Q 22.
Original : a ProFile Original : Butterfly Original : ThE bESt mEN wIN
Final : AOROoILE Final : CUuTfRgLz Final : SHDeBRTtMDnWH
************************ ************************* ***********************
Q 07. Q 15. Q 23.
Original : admiNStrAtiOn Original : Butterfly Original : ThE bESt mEN wIN
Final : ADMIiQTRrTIMN Final : DvTuEsFmY Final : SHDBbRTMDeWHi
*********************** ************************** ***********************
Q 08. Q 16. Q 24.
Original : SakESpHerE Original : Butterfly Original : ThE bESt mEN wIN
Final : XSaKXSGHeR Final : DsTrEpFjY Final : SHDeBRTtMDnWH
********************** ********************** *******************

Page 18 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
New Assignments Functions using Python
INTRODUCTION AND TYPE AND CALLING OF FUNCTIUONS
print("1.Default function used in : \nDisplay print(r1,", ",r2) #calling
Static Data/Menu Display/Choice Display") print("-"*25)
def FUN(): #definartion print("8. Function Arguments LIST")
print("Python") def FUN(a): #definartion
print("is") print(a)
print("FUN!") D=[1,2,3,5]
FUN() #calling FUN(D) #calling
print("-"*25) print("-"*25)
print("2. Parameterize/ Argumenta function used print("9. Function Arguments Tuple")
in : \nperform operation's") def FUN(a): #definartion
def FUN(a): #definartion print(a)
print("a is %d"%a) D=(1,2,3,5)
print("a*a is %d"%(a*a)) FUN(D) #calling
print("a**a is %d"%(a**a)) print("-"*25)
FUN(5) #calling print("10. Function Arguments String")
print("-"*25) def FUN(a): #definartion
print("3. Return Single Argument 1") print(a)
def FUN(a): #definartion D="DotPyEdu"
return a*a FUN(D) #calling
print(FUN(5)) #calling print("-"*25)
print("-"*25) print("11. Function Arguments Dictionary")
print("4. Return Single Argument 2") def FUN(a): #definartion
def FUN(a): #definartion print(a)
return a*a D={1:"PYTHON",2:"is",3:"Fun",5:"Function's"
r=FUN(5) #calling }
print(r) FUN(D) #calling
print("-"*25) print("12. Function with de
print("4. Return Multiple Argument 1") fult Argument")
def FUN(a): #definartion def FUN(a=10): #definartion
return a*a,a**3 print(a)
print(FUN(5)) #calling a=4
print("-"*25) print(a)
print("6. Return Multiple Argument 2 ") FUN(a) #calling
def FUN(a): #definartion print(a)
return a*a,a**3 print("13. Function with defult Argument")
r1,r2=FUN(5) def FUN(a,b=10): #definartion
print(r1,", ",r2) #calling print(a,",",b)
print("-"*25) a,b=4,13
print("7. Return Multiple Argument 2 using print(a,",",b)
index") FUN(a,b) #calling
def FUN(a): #definartion FUN(a) #calling
return a*a,a**3 FUN(b) #calling
r1=FUN(5)[0] FUN(b,a) #calling
r1=FUN(5)[1]
OUTPUT:
1.Default function used in : -------------------------
Display Static Data/Menu Display/Choice Display 2. Parameterize/ Argumenta function used in :
Python perform operation's
is a is 5
FUN! a*a is 25

Page 19 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
a**a is 3125 -------------------------
------------------------- 9. Function Arguments Tuple
3. Return Single Argument 1 (1, 2, 3, 5)
25 -------------------------
------------------------- 10. Function Arguments String
4. Return Single Argument 2 DotPyEdu
25 -------------------------
------------------------- 11. Function Arguments Dictionary
4. Return Multiple Argument 1 {1: 'PYTHON', 2: 'is', 3: 'Fun', 5: "Function's"}
(25, 125) 12. Function with defult Argument
------------------------- 4
6. Return Multiple Argument 2 4
25 , 125 4
------------------------- 13. Function with defult Argument
7. Return Multiple Argument 2 using index 4 , 13
125 , 125 4 , 13
------------------------- 4 , 10
8. Function Arguments LIST 13 , 10
[1, 2, 3, 5] 13 , 4

ASSIGNMENT OF FUNCTION
print("Q1. ") a+=2 print(a,":",b,"\n")
def switchover(A,N, split): b[0]=b[0]+5 a,b=4,8
K=0 print(a,":",b,"\n") print(a,":",b,"\n")
while K<N: a,b=4,[8] s(a,b)
if K<split : print(a,":",b,"\n") print(a,":",b,"\n")
A[K]+= K s(a,b) s(a)
else: print(a,":",b,"\n") print(a,":",b,"\n")
A[K]*= K print("="*30) s()
K+=1 print("Q4. ") print(a,":",b,"\n")
def display(A,N): def s(a, b): print("="*30)
K=0 a[0]+=2 print("Q7. ")
while K<N: b[0]+=5 def func(x,y):
if K%2== 0: print(a,":",b,"\n") if x[0]%y[0]==0 :
print(A[K],end="%") a,b=[4],[8] return x[0]+2
else: print(a,":",b,"\n") else:
print(A[K],"\n") s(a,b) return y[0]-1
K+=1 print(a,":",b,"\n") p,q=[20],[23];
H= [30,40,50,20,10,5] print("="*30) print(p,",",q)
switchover(H,6,3) print("Q5. ") q=func(p,q)
print(H) def s(a, b=7): print(p,",",q)
display(H,6) a+=2 print("="*30)
print("="*30) b*=5 print("Q8. ")
print("Q2. ") print(a,":",b,"\n") def func(x,y=10):
def s(a, b): a,b=4,8 if x%y==0 :
a+=2 print(a,":",b,"\n") return x+2
b*=5 s(a,b) else:
print(a,":",b,"\n") print(a,":",b,"\n") return y-1
a,b=4,8 s(a) p,q=20,23;
print(a,":",b,"\n") print(a,":",b,"\n") print(p,",",q)
s(a,b) print("="*30) q=func(p,q)
print(a,":",b,"\n") print("Q6. ") print(p,",",q)
print("="*30) def s(a=6, b=7): print("="*30)
print("Q3. ") a+=2 print("Q9. ")
def s(a, b): b*=5 def func(x,y=10):
Page 20 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
if x%y==0 : p=func(q) if(y<=20):
return x+2 print(p,",",q) print(temp,",",x,",",y)
else: q=func(p) a,b =50,20
return y-1 print(p,",",q) execute(b)
p,q=20,23; print("="*30) print(a,",",b)
print(p,",",q) print("Q11.") execute(b)
q=func(p,q) def execute(x,y=200): print(a,",",b)
print(p,",",q) temp=x+y print("="*30)
p=func(q) x+=temp print("Q13.")
print(p,",",q) if(y!=200): def execute(x,y=20):
print("="*30) print(temp,",",x,",",y) temp=x*y
print("Q10. ") a,b =50,20 x+=temp
def func(x,y=10): execute(b) if(y>=20):
if x%y==0 : print(a,",",b) print(temp,",",x,",",y)
return x+2 execute(a,b) a,b =50,20
else: print(a,",",b) execute(b)
return y-1 print("="*30) print(a,",",b)
p,q=20,23; print("Q12.") execute(a)
print(p,",",q) def execute(x,y=15): print(a,",",b)
q=func(p,q) temp=x+y
print(p,",",q) x+=temp
OUTPUT:
Q1. [6] : [13] Q7. ===============
[30, 41, 52, 60, 40, 25] [6] : [13] [20] , [23] Q11.
30%41 ================== [20] , 22 50 , 20
52%60 Q5. ================ 70 , 120 , 20
40%25 4:8 Q8. 50 , 20
================= 6 : 40 20 , 23 =================
Q2. 4:8 20 , 22 Q12.
4:8 6 : 35 ================ 35 , 55 , 15
6 : 40 4:8 Q9. 50 , 20
4:8 ================= 20 , 23 35 , 55 , 15
================= Q6. 20 , 22 50 , 20
Q3. 4:8 9 , 22 ==============
4 : [8] 6 : 40 ============== Q13.
6 : [13] 4:8 Q10. 400 , 420 , 20
4 : [13] 6 : 35 20 , 23 50 , 20
================ 4:8 20 , 22 1000 , 1050 , 20
Q4. 8 : 35 9 , 22 50 , 20
[4] : [8] 4:8 9,9
===============

New Syllabus Python (Randomize Output Assignment)


import random
Que. 1 . Guess=65
N=20 for I in range(1,5):
for i in range(4): New=Guess+random.randrange(0,I)
Guessnum=random.randrange(0,N-10)+10 print(chr(New),end=' ')
print(Guessnum,end=' ') # Output Options :
print() i. A B B C ii. A C B A
# Output Options : iii. B C DA iv. C A B D
#10 to 19 , 4 numbers print()
Que.2 Que.3.
Page 21 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
n=1 print()
VAL=12 #Output Options:
Rnd=8 + random.randrange(0,VAL) * 1 i. DEL: CHN : KOL : ii. CHN : KOL : CHN :
while(n<=Rnd): iii. KOL : BOM : BNG : iv. KOL : CHN : KOL :
print(n,end=" ") Que.10.
n+=1 Area=["NORTH","SOUTH","EAST","WEST"]
print() for I in range(3):
# Output Options : ToGo=random.randrange(0,2) + 1
i. 1 2 3 4 5 6 7 8 9 10 11 12 13 ii. 0 1 2 3 print(Area[ToGo],end=":")
# iii. 1 2 3 4 5 iv. 1 2 3 4 5 6 7 8 print()
Que.4. #Output Options:
RN=random.randrange(0,4)+5; i. SOUTH : EAST : SOUTH :ii. NORTH : SOUTH : EAST :
for I in range(1,RN): iii. SOUTH : EAST : WEST : iv. SOUTH : EAST : EAST :
print(i,end=' ') Que.11.
# Output Options: Num=13
i. 0 1 2 ii. 1 2 3 4 5 6 7 8 RndNum = random.randrange(0,Num) +13;
iii. 4 5 6 7 8 9 iv. 5 6 7 8 9 10 11 12 for N in range(1,RndNum):
print() print(N,end=" ")
Que.5. print()
Score=[ 25,20,34,56, 72, 63] Que.12.
Myscore = Score[2 + random.randrange(0,2)] r=random.randrange(0,20)+random.randrange(0,2)
print(Myscore) print(r)
# Output Options : Que.13.
i. 25 ii. 34 iii. 20 iv. None of the above #fill in the blanks for the statement1 with the help of
Que.6. random function
Marks = [99, 92, 94, 96, 93, 95] #if the number generated by the random number is
MyMarks = Marks [1 + random.randrange(0,2) ] supposed to be between the range of 25-2025.
print(MyMarks) #r=_______________//statement 1
# Output Options : print(r)
i. 99 ii. 94 iii. 96 iv. None of the above Que.14.
#fill in the blanks for the statement1 with the help of
Que.7. random function
Disp=22 #if the number generated by the random number is
Rnd=random.randrange(0,Disp)+15 supposed to be between the range of 20-2000.
N=1 #r=_______________//statement 1
for I in range(3,Rnd,4): print(r)
print(N,end=" ") Que.14.1.
N+=1 #fill in the blanks for the statement1 with the help of
print() random function
#Output Options: #if the number generated by the random number is
i. 1 ii. 1 2 3 4 iii. 1 2 iv. 1 2 3 supposed to be between the range of 41-441.
Que.8. #r=_______________//statement 1
N=37 print(r)
Guess_num=random.randrange(0,N-8)+38 Que.15.
print(Guess_num) low=25
#what maximum and minimum values the program could point =5
possibly display? for i in range (1,5):
Que.9. Number=low + random.randrange(0,point);
city= [ "DEL", "CHN", "KOL", "BOM", "BNG"] print(Number,end="")
for I in range(1,4): point-=1;
Fly = random.randrange(0,2) + 1 ; print()
print( city[Fly] ,end=":") #Output Options:
Page 22 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
i. 29: 26:25 :28 : ii. 24: 28:25 :26 : Que.21.
iii. 29: 26:24 :28 : iv. 29: 26:25 :26 : LIMIT = 4
Que.16. Points = 100 +random.randrange(0,LIMIT);
Max=3 for p in range(Points,99,-1):
Div=1+random.randrange(0,Max) print(p,end="#")
for N in range(1,5): print()
print(100%Div,end="#") #Output Options:
print() i. 103#102#101#100# ii. 100#101#102#103#
#Output Options: iii. 100#101#102#103#104# iv. 104#103#102#101#100#
i. 0#0#0#0# ii. 1#1#1#1# iii. 2#2#2#2# iv. 3#3#3#3# Que.22.
Que.17. #if the value of N given by the user is 20,
MIN = 25 #what maximum and minimum values the program could
SCORE = 10 possibly display?
for i in range (1,5): N=20
Num = MIN + random.randrange(0,SCORE) Guessnum=random.randrange(0,N-10)+10;
print(Num,end=":") print(Guessnum)
SCORE-=1; Que.23.
print() High=4
#Output Options: Guess=random.randrange(0,High) +50
i. 34:31:30:33: ii. 29:33:30:31: for C in range(Guess, 56):
iii. 34:31:30:31: iv. 34:31:29:33: print(C,end="#")
Que.18. #Output Options:
Max=3; i 50 # 51 # 52 # 53 # 54 # 55 # ii 52 # 53 # 54 # 55 #
Number=50+random.randrange(0,Max) iii 53 # 54 # iv 51 # 52 # 53 # 54 # 55
for P in range(Number,50-1,-1): print()
print(P,end="#") Que.24.
print() LOW = 15
#Output Options: POINT =5
i. 53#52#51#50# ii. 50#51#52# for I in range (1,5):
iii. 50#51# iv. 51#50# Number = LOW + random.randrange(0,POINT)
Que.19. ") print(Number ,end=":")
MAX = 3; POINT-=1
digit =80 + random.randrange(0,MAX ) print()
for R in range (digit,80-1,-1): #Output Options:
print(R,end="$") i.19:16:15:18: (ii. 14:18: 15:16:
print() iii. 19:16:14:18: (iv. 19:16:15:16:
#Output Options: Que.25.
i. 83$82$81$80$ ii. 80$81$82$ iii. 80$81$ iv. 81$80$ Max=4;
Que.20. Mynum=20+random.randrange(0,Max);
p=99 for N in range (Mynum,26):
q=999 print(N,end="*")
x=random.randrange(0,3)+4 print()
y=random.randrange(0,2)+2 #Output Options:
for i in range(x): i. 20*21*22*23*24*25* ii. 22*23*24*25*
print("#",end="") iii. 23*24* iv. 21*22*23*24*25
print(p,"-",end="") Que. 26.
for i in range(x): Score=[25,20,34,56, 72, 63]
print("@",end="") n=2
print(q) Myscore = Score[1 + random.randrange(0,n)]+4;
#Output Options: print(Myscore)
i. ##99-@999 ii. ##99-@@999 #Output Options:
iii. ######99-@@999 iv. ####99-@@@ i. 25 ii. 72 iii. 24 iv. None of the above
Page 23 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
Que.27. Chance=random.randrange(0,2)+10
serial=['E', 'X', 'A', 'M'] for I in range (2):
number=[ 69, 66, 67, 68] N=random.randrange(0,2)
print(number[random.randrange(0,3)]) print(Arr[N]+Chance,end="*")
for i in range (4): print()
print(serial[2+ random.randrange(0,2) - 1 ]) #Output Options:
#Output Options: i. 9*6* ii. 19*17* iii. 19*16* iv. 20*16*
i. 66AAXA ii. 67AAAM iii. 67XXAX iv. 69AXXA Que. 31.
Que.28. A="WELCOME"
p=["Computer","Mouse","Keyboard","Pen Drive"] ToGo=2
for i in range (1, 4): for I in range (len(A)):
print(p[random.randrange(i)],end=" ") ToGo=random.randrange(0,2*2) +1;
print() print(A[ToGo],end=":")
#Output Options: print()
# i. Mouse Keyboard Pen drive ii. Computer Computer Keyboard #Output Options:
iii. Computer Computer Mouse iv. None of the above i. W: E: L: C: O: M: E: ii. E: C: E: E: C: C: E:#
Que.29. #iii.E: C: E: E: C: C: O: iv. C: C: C: E: E: C: C:
serial=['A', 'B', 'C', 'D'] print("-"*31)
number=[2, 6, 7, 3 ] Que.32.
print(" The DATA is : ",end="") X =[100,75,10,125]
print(serial [random.randrange(0,3)],end="") Go =random.randrange(0,2)+2
for i in range ( 4): for i in range (Go,4):
print(number[2+ random.randrange(0,2) - 1 ],end="") print(X[i],end="$$")
#Output Options: #Output Options:
i. The winner is : A2776 ii. The winner is : D6766 i. 100$$75 ii. 75$$10$$125$$
#iii. The winner is : B6767 iv. The winner is : C3672 iii. 75$$10$$ iv.10$$125$
Que.30.
Arr=[ 9,6]
OUTPUT
1. 10,19 7. ii 13. 18. iv 24. d 30. ii
2. i 8. 38,66 random(0,1981)+20 19. iv 25. a,b 31. iii
3. iv 9. ii,iv 14. random(0,2001)+ 20. iii 26. iii 32. b,c,d
25
4. ii 10. i,iv 21. i 27. I,iii,iv 33. iv
15. iv
5. ii 11. 1 to 13/25 22. 19,10 28. ii,iii
16. i,ii
6. ii 12. 0,20 23. i,ii 29. iii
17. ii,iii

Page 24 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

#Example 1:
import matplotlib.pyplot as p1
p1.plot([1,7,3,8],[2,4,6,8])
p1.ylabel('Y Range')
p1.xlabel('X Range')
p1.title("First Plot")
p1.show()
#Example 2:
import matplotlib.pyplot as p1
p1.plot([1,7,3,8,11],[2,4,6,8,11])
p1.ylabel('Y Range')
p1.xlabel('X Range')
p1.title("First Plot")
p1.show()
#Example 3:
x=[1,2,3,4,5]
y=[6,7,8,9,10]
p1.xlabel("DATA FROM A")
p1.ylabel("DATA FROM B")
p1.title("DATA ALL")
p1.bar(x,y,width=[0.3,0.2,0.4,0.1,0.5],color=["red","black","b","g","y",])#width=0.1 to 0.9
p1.show()
Page 25 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
#Example 4:
import numpy as np
x=np.arange(0,10,2)
y=[6,7,8,9,10]
p1.xlabel("DATA FROM A")
p1.ylabel("DATA FROM B")
p1.title("DATA ALL")
p1.bar(x,y,width=0.2,color="b")
p1.bar(x+0.3,y,width=0.2,color="r")
p1.show()
#Example 5:
import numpy as np
x=np.arange(10,100,20)
print(x)
L=["Python","PHP","CSS","C++","HTML"]
mcolor=['red','black','pink','yellow','silver']
p1.title("DATA ALL")
p1.pie(x,labels=L,colors=mcolor,autopct="%05.3f%%",explode=[0,0.2,0,0.1,0])
p1.show()
#Example 6:
import numpy as np
x=np.arange(10,100,20)
print(x)
L=["Python","PHP","CSS","C++","HTML"]
mcolor=['red','yellow','silver','black','pink']
myex=[0,0.2,0,0.1,0]
p1.title("DATA ALL")
p1.pie(x,labels=L,colors=mcolor,autopct="%05.3f%%",explode=myex)
p1.show()
#Example 7:
x=[ 1,2,3, 4,5,6, 6,7,8, 8, 9,10]
y=[13,7,2,11,0,3,17,1,5,11,22,14]
print(x)
print(y)
p1.xlabel("Overs",color="red")
p1.ylabel("Score",color="blue")
p1.title("IPL 2019")
p1.plot(x,y,'black')
p1.savefig("my pi chart .jpeg")
p1.show()
PLOT UNSOLVE PROBLEMS
1. Bar chart is drawn(using pyplot) to represent data of various countries and growth_rate_countrys.
countrys =['BRAZIL','US','BRITAIN','UAE','BANG','KENYA','AFRICA','AUST']
growth_rate_countrys =[24,57,48,60,15,41,19,66]
3. Line chart is drawn(using pyplot) to represent data of various cities,
Population.
cities=["GHAZIABAD","DELHI","KANPUR","JAIPUR","UDAIPUR","MUMBAI","GOA","P
UNE","AHEMBAD"]
population=[10,12.5, 16.18,15.17,19.89, 16.7,8.9,10.12,13.12]
4. Bar chart is drawn(using pyplot) to represent data of various isps and profit _ rate.
isps=["AIRTEL","VODAFONE","AIRCELL","IDIA","BSNL","JIO","TATA","VSNL","UNICOM"]
profit _ rate =[10,13,25,9,5,7,19,11,17]
5. Pie chart is drawn(using pyplot) to represent data of various cars and growth_rate_comp.
cars=["MARUTI","SUZUKI","FORD","KIA","MG","TOYTA","TATA","BMW","AUDI"]
growth_rate_comp=[10,13,25,9,5,7,19,11,17]

Page 26 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

FILE HANDLING BASIC PROGRAMS Set A Solution


1. WAP to read and count character from data.txt file :
i. Character Upper/ Lower Character
ii. Digit Character Characters/Symbol/ Spaces
iii. Words/ Lines
iv. Vowel /Consonant Character
ANS:
i/ii:
f1=open("data.txt","r")
s=f1.read()
print(s)
count=0
for ch in s:
if ch.isupper()==True: #ch.islower()/ch.isdigit()/ch.isspace/ch==’\n\ for line
count+=1
print(count)
words=count+1 # After Space Count
print(words)
Symbol (Special Characters):
f1=open("data.txt","r")
s=f1.read()
count=0
for ch in s:
if ch.isalnum()==False:
count+=1
print(count)
iii:
Words
f1=open("data.txt","r")
s=f1.read()
print(s)
words=s.split()
Page 27 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON
print(words,”, ”,len(words))
Line
f1=open("data.txt","r")
s=f1.readlines()
print(s)
print(s,”, ”,len(s))
iv:
f1=open("data.txt","r")
s=f1.read()
countV=0
countC=0
for ch in s:
if ch.isalnum()==True:
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':ch in “aeiouAEIOU”
countV+=1
else:
countC+=1
print("V: ",countV,", C= ", countC)

2. WAF to read and count Words start with from text file : Upper /Lower / Digits / Special / Vowel /
Consonant Character
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
words=s.split()
print(words,”, ”,len(words))
for word in words:
if word[0].isupper()==True: #same Q1 part 1st
count+=1
print(count)
3. WAF to read and count Words end with from text file : Upper /Lower / Digits / Special / Vowel /
Consonant/User Define Character
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
words=s.split()
print(words,”, ”,len(words))
for word in words:
if word[-1].isupper()==True: #same Q1 part 1st
count+=1
print(count)
4. WAF to read and count Words start and end with from text file : Upper /Lower / Digits / Special / Vowel /
Consonant/User Define Character
ANS:
f1=open("data.txt","r")
s=f1.read()

Page 28 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
print(s)
words=s.split()
print(words,”, ”,len(words))
for word in words:
if word[-1].isupper()==True and word[0].isupper()==True: #same Q1 part 1st
count+=1
print(count)
5.WAF to count the word present in a text file DATA.TXT. Word: - like this/This, My, Me, He, She, to, the, do,
Mr. and Mrs.
ANS:
f1=open("data.txt","r") print(words,”, ”,len(words))
s=f1.read() for word in words:
print(s) if word==sword:
sword=input(“Enter Your search Word: ”) count+=1
words=s.split() print(count)

FILE HANDLING FOR BOARD EXAM


Q1. WAF to count the number of character present data.txt as : „A‟, „t‟, „T‟, „E‟, „I‟, „i‟.
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
count=0
sch=input(“Enter Any Character: ”)
for ch in s:
if ch==sch[0]: #sch[0] read first character from input string
count+=1
print(count)
Q2. WAF to count the number of words in a text file „DATA.TXT‟ which is started/ended with „A‟, „t‟, „T‟, „E‟, „I‟,
„i‟.
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
count=0
words=s.split()
print(words,”, ”,len(words))
for word in words:
if word[0]== „A‟: # word[-1] for end character/ endswith or startswith method
count+=1
print(count)
Q3. WAF to count the number of lines in a text file „DATA.TXT‟ which is started/ended with „A‟, „t‟, „T‟, „E‟, „I‟, „i‟.
ANS:
f1=open("data.txt","r")
lines=f1.readlines()
print("All Data of file in lines: \n",lines)
count=0
i=1
print("="*30)
for line in lines:
print("Line %d : %s ,length is : %d"%(i,line,len(line)))
i+=1
if line[0]=='t': # line[-1]=='t':
Page 29 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON

count+=1
print("Lines start with 't' is ",count)
Q4. WAF to count the number of words in a text file „DATA.TXT‟ which is starting/ended with an word
„The‟, „the‟, „my‟, „he‟, „they‟.
ANS:
f1=open("data.txt","r")
s=f1.read()
print("All Data of file in string : \n",s)
print("="*30)
count=0
words=s.split()
print("All Words: ",words,", length is ",len(words))
for word in words:
if word.startswith("the")==True: # word.endswith(“the”)
count+=1
print("Words start with 'the' is ",count)
Q5. WAF to count the number of line in a text file „DATA.TXT‟ which is starting/ended with an word „The‟,
„the‟, „my‟, „he‟, „they‟.
ANS:
f1=open("data.txt","r")
s=f1.read()
print("All Data of file in string : \n",s)
print("="*30)
f1=open("data.txt","r")
lines=f1.readlines()
print("All Data of file in lines: \n",lines)
count=0
i=1
print("="*30)
for line in lines:
print("Line %d : %s ,length is : %d"%(i,line,len(line)))
i+=1
if line.startswith("the")==True: # line.endswith(“the”)
count+=1
print("Lines start with 'the' is ",count)
Q6. WAF to read data from a text file DATA.TXT, and display those words, which are less than 4 characters.
ANS:
f1=open("data.txt","r") for word in words:
s=f1.read() if len(word)==4:
print(s) print(word)
count=0 count+=1
words=s.split() print(count)
print(words,”, ”,len(words))
Q7. WAF to read data from a text file DATA.TXT, and display words with number of characters.
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
words=s.split()
print(words,”, ”,len(words))
for word in words:
print(word,”, ”,len(word))

Page 30 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

Q8. WAF to read data from a text file DATA.TXT, and display each words with number of vowels and
consonants.
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
countV=0
countC=0
words=s.split()
print(words,”, ”,len(words))
for word in words:
countV=0
countC=0
for ch in word:
if ch.isalnum()==True:
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
countV+=1
else:
countC+=1
print("Word : ",word,", V: ",countV,", C= ", countC)
Q9. WAF to read data from a text file DATA.TXT, and display word which have maximum number of vowels
characters.
ANS:
f1=open("data.txt","r")
s=f1.read()
print(s)
countV=0
countC=0
words=s.split()
print(words,", ",len(words))
maxV=0
final=""
for word in words:
countV=0
for ch in word:
if ch.isalnum()==True:
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
countV+=1
if maxV<countV:
maxV=countV
final=word
print("Final : ",final,", maxV: ",maxV)
Q10. WAF to read data from a text file DATA.TXT, and display word which have maximum/minimum
characters.
Ans:
f1=open("data.txt","r") minfinal=""
s=f1.read() maxfinal=""
print(s) for word in words[1:]:
words=s.split() length=len(word)
print(words,", ",len(words)) if maxC<length:
maxC=len(words[0]) maxC=length
minC=len(words[0]) maxfinal=word

Page 31 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

if minC>length: print("Max word : ",maxfinal,", maxC:


minC=length ",maxC)
minfinal=word print("Min word : ",minfinal,", minC:
",minC)
FILE HANDLING UNSOLVE PROBLEMS
1. Write a Function to count the number of character present data.txt as : „A‟, „t‟, „T‟, „E‟, „I‟, „i‟.
2. Write a Function to count the number of words in a text file „DATA.TXT‟ which is started with „A‟, „t‟, „T‟,
„E‟, „I‟, „i‟.
3. Write a Function to count the number of lines in a text file „DATA.TXT‟ which is started with „A‟, „t‟, „T‟,
„E‟, „I‟, „i‟.
4. Write a Function to count the number of words in a text file „DATA.TXT‟ which is starting with an word
„The‟, „the‟, „my‟, „he‟, „they‟.
5. Write a Function to count the number of words in a text file „DATA.TXT‟ which is ended with „A‟, „t‟, „T‟,
„E‟, „I‟, „i‟.
6. Write a Function to count the number of lines in a text file „DATA.TXT‟ which is ended with „A‟, „t‟, „T‟,
„E‟, „I‟, „i‟.
7. Write a Function to count the number of words in a text file „DATA.TXT‟ which is ended with an word
„The‟, „the‟, „my‟, „he‟, „they‟.

LINEAR SEARCH | BINARY SEARCH


LINEAR SEARCH SAMPLE 1: print(c)
x =[1,2,3,5,7,89,3,62,34,13,5,7,9] if c>0:
data = 89 print("Yes Present")
found =0 else:
for i in x: print("Not Present")
if i ==data: print("#------------LS-----Indirect----------")
found =1 d=[2,3,2,4,5,6,7,1,1,11,3,4,9]
if(found ==0): e=int(input("E= "))
print("Data not found") c=0
else: for i in d:
print("Data found") if i==e:
LINEAR SEARCH SAMPLE 2: c+=1
print("#------------Direct-----------") if c>0:
d=[2,3,2,4,5,6,7,1,1,11,3,4,9] print("Yes Present")
e=int(input("e= ")) else:
c=d.count(e) print("Not Present")
-------------------------------------
BINARY SEARCH SAMPLE 1: found =1
x =[1,2,3,5,7,8,9,10,12,14,15,18,20,22] if(x[mid]<data):
data = 89 first=mid+1
found =0 if(x[mid]>data):
first=0 last = mid-1
last =13 if(found ==0):
while (first<=last and found ==0): print("Data not found")
mid = int((first+last)/2) else:
# print(mid) print("Data found")
if(x[mid]==data): BINARY SEARCH SAMPLE 2:

Page 32 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

#------------BS--------------- print("Mid: ",Mid,", B: ",B,", E: ",E)


DATA=[1,2,3,4,5,6,7,8,9,11,13,14,19,45] if DATA[Mid]==e:
e=int(input("e= ")) #12 f=1
length=len(DATA) break
B=0 if DATA[Mid]>e:E=Mid-1
E=length-1 if DATA[Mid]<e:B=Mid+1
Mid=0 if f==1:
f=0 print("Yes Present")
while B<=E: else:
x=(B+E)/2 print("Not Present")
Mid=int(x)
-------------------------------------
CONCAT TWO LIST print(length)
x =[3,56,2,56,78,56,34,23,4,78,8,123,45] print(DATA)
y = [23,2,3,4] INSERT ITEM IN POS
# z=[] #--------insert in POS--------
# for i in x: DATA=[1,2,3,4,5,6,7]
# z.append(i) print(DATA)
# for i in y: le=len(DATA)
# z.append(i) print(le)
z= x+y e=int(input("e= ")) #12
#display concatenated list pos=int(input("pos= ")) #4
for i in z: DATA.append(None)
print(i,end=" ") le=len(DATA)
INSERT ITEM IN END for i in range(le-1,pos,-1):
#----insert in end--------------- DATA[i]=DATA[i-1]
DATA=[1,2,3,4,5,6,7] print(DATA)
print(DATA) DATA[pos]=e
length=len(DATA) le=len(DATA)
print(length) print(le)
e=int(input("e= ")) #12 print(DATA)
DATA.append(None) INSERT ITEM IN SORTED LIST
length=len(DATA) #---insert in sorted list--------
print(length) DATA=[1,2,3,4,6,7]
print(DATA) print(DATA)
DATA[length-1]=e le=len(DATA)
print(DATA) e=int(input("e= ")) #5
INSERT ITEM IN BEG pos=0
#--------insert in beg-------- DATA.append(None)
DATA=[1,2,3,4,5,6,7] le=len(DATA)
print(DATA) for i in range(le):
length=len(DATA) if DATA[i]>e:
print(length) pos=i
e=int(input("e= ")) #12 break
DATA.append(None) print(pos)
length=len(DATA) for i in range(le-1,pos,-1):
for i in range(length-1,0,-1): DATA[i]=DATA[i-1]
DATA[i]=DATA[i-1] DATA[pos]=e
print(DATA) length=len(DATA)
DATA[0]=e print(DATA)
length=len(DATA)

Page 33 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

BUBBLE SORT | MERGE SORT INSERTION SORT | SELECTION SORT

Bubble Sort
def bubblesort(list): list[idx] = list[idx+1]
# Swap the elements to arrange in order list[idx+1] = temp
for iter_num in range(len(list)-1,0,-1): list = [19,2,31,45,6,11,121,27]
for idx in range(iter_num): bubblesort(list)
if list[idx]>list[idx+1]: print(list)
temp = list[idx]
Merge Sort
def merge(left_half,right_half): right_half.remove(right_half[0])
res = [] if len(left_half) == 0:
while len(left_half) != 0 and len(right_half) != 0: res = res + right_half
if left_half[0] < right_half[0]: else:
res.append(left_half[0]) res = res + left_half
left_half.remove(left_half[0]) return res
else: unsorted_list = [64, 34, 25, 12, 22, 11, 90]
res.append(right_half[0]) print(merge_sort(unsorted_list))
Insertion Sort
def insertion_sort(InputList): InputList[j+1] = InputList[j]
for i in range(1, len(InputList)): j=j-1
j = i-1 InputList[j+1] = nxt_element
nxt_element = InputList[i] list = [19,2,31,45,30,11,121,27]
# Compare the current element with next one insertion_sort(list)
while (InputList[j] > nxt_element) and (j >= 0): print(list)
Selection Sort
def selection_sort(input_list): # Swap the minimum value with the compared value
for idx in range(len(input_list)): input_list[idx], input_list[min_idx] =
min_idx = idx input_list[min_idx], input_list[idx]
for j in range( idx +1, len(input_list)): l = [19,2,31,45,30,11,121,27]
if input_list[min_idx] > input_list[j]: selection_sort(l)
min_idx = j print(l)

SEARCH UNSOLVE PROBLEMS


1. Write a Recursive function in python LenoirSearch(Arr1D,l,R,X) to search the given element X to be searched
from the List Arr1D having R elements where l represents lower bound and R represents upper bound.
2. Write a Recursive function in python BinarySearch(Arr1D,l,R,X) to search the given element X to be searched
from the List Arr1D having R elements where l represents lower bound and R represents upper bound.
3. Write a Recursive function in python LenoirSearch(Arr2D,N,M,X) to search the given element X to be
searched from the Nested List(2D Array) Arr2D having R elements where N represents lower bound and M
represents upper bound.
4. Write a Recursive function RecurSum(n) in python to calculate and return the factorial of number n passed to
the parameter.
5. Write a Recursive function RecurNaturalDis (n) in python to Print n natural numbers.
6. Write a Recursive function RecurNaturalSum(n) in python to Sum of n natural numbers.
7. Write a Recursive function RecurDigitSum(n) in python to Sum of digits of a given number
8. Write a Recursive function RecurPow(x,n) in python to calculate and return the xn.

Page 34 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
QUEUE | STACK
Stack single REC:
#function to add element at the end of list x=[]
def push(stack,x): choice=0
stack.append(x) while (choice!=4):
print(x) print("\n\t\t\t stack menu \n\t1. push \n\t2. pop \n\t3.
#function to remove last element from list Display \n\t4. Exit")
def pop(stack): choice = int(input("Enter your choice"))
n = len(stack)
if(n<=0): if(choice==1):
print("Stack empty....Pop not possible") value = int(input("Enter value "))
else: push(x,value)
stack.pop() if(choice==2):
#function to display stack entry pop(x)
def display(stack): if(choice==3):
if len(stack)<=0: display(x)
print("Stack empty...........Nothing to display") if(choice==4):
for i in stack: print("You selected to close this program")
print(i,end=" ") -----------------------------------------------
#main program starts from here
Stack Multi Rec:
#function to add element at the end of list Item_code=0
def push(stack,x): choice=0
stack.append(x) while (choice!=4):
print(x) print("\n\t\t\t stack menu \n\t1. push \n\t2. pop \n\t3.
#function to remove last element from list Display \n\t4. Exit")
def pop(stack): choice = int(input("Enter your choice"))
n = len(stack) if(choice==1):
if(n<=0): Item_name=input("Enter Item_name= ")
print("Stack empty....Pop not possible") Item_code=int(input("Enter Item_code= "))
else: value=[Item_name,Item_code]
stack.pop() #print (value)
#function to display stack entry push(x,value)
def display(stack): if(choice==2):
if len(stack)<=0: pop(x)
print("Stack empty...........Nothing to display") if(choice==3):
for i in stack: display(x)
print(i,end=" ") if(choice==4):
#main program starts from here print("You selected to close this program")
x=[] --------------------------------------------------
Item_name=""
Queue single REC:
#function to add element at the end of list #main program starts from here
def add_element(Queue,x): x=[]
Queue.append(x) choice=0
#function to remove last element from list while (choice!=4):
def delete_element(Queue): print("\n\tQueue menu \n\n\t1. Add Element \n\t2.
n = len(Queue) Delete Element \n\t3. Display \n\t4. Exit")
if(n<=0): choice = int(input("\n Enter your choice : "))
print("Queue empty....Deletion not possible") if(choice==1):
else: value = int(input("Enter value : "))
del(Queue[0]) add_element(x,value)
#function to display Queue entry if(choice==2):
def display(Queue): delete_element(x)
if len(Queue)<=0: if(choice==3):
print("Queue empty...........Nothing to display") display(x)
for i in Queue: if(choice==4):
print(i,end=" ") print("You selected to close this program")

Page 35 of 41 EDUCATION FOR


EVERYONE
DoyPyEdu PLAY WITH PYTHON
-----------------------------------------------------
Queue multi REC:
#function to add element at the end of list #main program starts from here
def add_element(Queue,x): x=[]
Queue.append(x) choice=0
#function to remove last element from list while (choice!=4):
def delete_element(Queue): print("\n\tQueue menu \n\n\t1. Add Element \n\t2.
n = len(Queue) Delete Element \n\t3. Display \n\t4. Exit")
if(n<=0): choice = int(input("\n Enter your choice : "))
print("Queue empty....Deletion not possible") if(choice==1):
else: value = int(input("Enter value : "))
del(Queue[0]) add_element(x,value)
#function to display Queue entry if(choice==2):
def display(Queue): delete_element(x)
if len(Queue)<=0: if(choice==3):
print("Queue empty...........Nothing to display") display(x)
for i in Queue: if(choice==4):
print(i,end=" ") print("You selected to close this program")
******************

Page 36 of 41 EDUCATION FOR


EVERYONE
DoyPyEdu PLAY WITH PYTHON
DATA LINK LIST UNSOLVE PROBLEMS
1. Write a function in Python INSERTQueue(Arr,data) for performing insertion operations in a Queue. Arr1D is
the list used for implementing Queue and data is the value to be inserted.
2. Write a function in Python DELETEQueue (Arr) for performing deletion operations in a Queue. Arr1D is the
list used for implementing Queue and data is the value to be inserted.
3. Write a function in Python, INSERTQueue (Arr,data) and DELETEQueue (Arr) for performing insertion and
deletion operations in a Queue. Arr1D is the list used for implementing queue and data is the value to be inserted.
4. Write a function in Python PUSHSStack(Arr,data) for performing insertion operations in a Stack. Arr1D is the
list used for implementing Stack and data is the value to be inserted.
5. Write a function in Python POPStack(Arr) for performing deletion operations in a Stack. Arr1D is the list used
for implementing Stack and data is the value to be inserted.
6. Write a function in Python PUSHStack (Arr,data) and POPStack (Arr) for performing insertion and deletion
operations in a Stack. Arr1D is the list used for implementing Stack and data is the value to be inserted.
7. Write a function in Python INSERTQueue(Arr,*data) for performing insertion operations in a Queue. Arr1D is
the list used for implementing Queue and multiple data is the value to be inserted.
8. Write a function in Python PUSHSStack(Arr,*data) for performing insertion operations in a Stack. Arr1D is the
list used for implementing Stack and multiple data is the value to be inserted.

Page 37 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON
MYSQL
Fill-ups (Solve)
1. SQL stands for ______________. (Structure Query Language)
2. Two features of Database are integrity and _________.(Share/time saving/security)
3. Database is the collection of __________.(Table/ Records/ Data)
4. Table is the collection of __________.(Data/ Information/ Row/ Tuple)
5. One of the use of database is ___________.(Sharing/analyses /access)
6. In RDBMS the character R and S stands for _________ and _________.(Relational, System)
7. Duplication of data is a one of the term of DBMS __________.(Data Redundancy)
8. What is the solution of Data Redundancy by using ____________ clause.(Unique)
9. What type of SQL commands used to modify structure of table? (DDL)(Alter)
10. What type of SQL commands used to modify data/information in table? (DML)(Update)
11. What type of SQL commands used to modify data type and size of a field in a Table? (DDL)(Alter)
12. DDL based on __________ and DML based on ________________. (Structure/Attribute/ degree ,
Information/row/tuple/Data/ Cardinality)
13. The layers of data independency are ____________and __________. (logical, Physical)
14. Numbers of fields in table are known as __________. (Attribute/ degree)
15. Key Features of Primary key are ___________ and ________.(Unique, Not null)
16. Drop command is the part of ________. (DDL)
17. Alter command is the part of ________. (DDL)
18. Create command is the part of ________. (DDL)
19. Update command is the part of ________. (DML)
20. Delete command is the part of ________. (DML)
21. Insert command is the part of ________. (DML)
22. Features of alter commands are Add ,__________ and ________(Modify ,Drop)
23. Aggregate functions are ____,______,______, ______ and avg(). (count(*),count(FN),,Min(),Max(),sum())
Differentiate between Explain with example (Unsolved)
1. DML and DDL 7. In and not in
2. DML and TCL 8. Like “Char/string%” and Like “%Char/string%”
3. DDL and TCL 9. Like “Char/string%” and Like “%Char/string”
4. Char and Varchar 10. Like “%Char/string” and Like “%Char/string%”
5. Drop and Delete command 11. Delete and Truncate command
6. Count(Field Name/*) and count (distinct (field 12. Alter and Update
Name))/ count (distinct field Name) 13. AND and OR

Descriptive Explain with example (Unsolved)


Write Short note Using Example:
1. Between clause 6. Group by clause
2. Order by clause 7. Having clause
3. Where clause 8. Aggregate functions
4. Join clause 9. Logical operators
5. Like clause 10. Relational Operators
1. Can you modify the field name in table a table? Explain with example (NO)
2. Can you modify the Data Type of a field in table a table? Explain with example (Yes)
3. Can you modify the size of a field in table a table? Explain with example (Yes)
Page 38 of 41 EDUCATION FOR EVERYONE
DoyPyEdu PLAY WITH PYTHON

SQL OUTPUT QUESTIONS

SAT 1 (CREATE TABLE COMMAND)


1. CREATE TABLE STUDENT(ROLLNO INT(4),NAME CHAR(30), CLASS INT(3),SECTION CHAR(3),
AGE INT(2),FEE INT(4));
2. CREATE TABLE STUDENT(ROLLNO INT(4) PRIMARY KEY,NAME CHAR(30), CLASS INT(3),
SECTION CHAR(3),AGE INT(2),FEE INT(4) NOT NULL);
3. CREATE TABLE STUDENT(ROLLNO INT(4) UNIQUE,NAME CHAR(30), CLASS INT(3),SECTION
CHAR(3),AGE INT(2),FEE INT(4) DEFAULT 2000);
4. CREATE TABLE STUDENT(ROLLNO INT(4) UNIQUE,NAME CHAR(30), CLASS INT(3),SECTION
CHAR(3),AGE INT(2) CHECK AGE>7,FEE INT(4) DEFAULT 2000);
5. CREATE TABLE STUDENT(ROLLNO INT(4) UNIQUE,NAME CHAR(30), CLASS INT(3),SECTION
CHAR(3) DEFAULT “A”,AGE INT(2) CHECK AGE>10,FEE INT(4) DEFAULT 2000);
6. CREATE TABLE STUDENT(ROLLNO INT(4) UNIQUE,NAME CHAR(30), CLASS INT(3) CHECK
CLASS>7,SECTION CHAR(3) DEFAULT “A”,AGE INT(2) CHECK AGE>7,FEE INT(4) DEFAULT
2000);
7. CREATE TABLE EMPLOYEE (EMPNO INT(3) PRIMARY KEY, EMPNAME CHAR(20)
UNIQUE,CITY CHAR(20) DEFAULT "DELHI",AGE INT (3) CHECK AGE>10, SALARY INT (7,2)
NOT NULL);
8. CREATE TABLE LIBRARY (BOOKNO CHAR(7),BOOK_NAME CHAR(30),COST INT(4), ROLLNO
INT(4),FINE INT(4))
9. CREATE TABLE LIBRARY (BOOKNO CHAR(7) PRIMARY KEY ,BOOK_NAME CHAR(30),COST
INT(4) NOTNULL,ROLLNO INT(4) UNIQUE,FINE INT(4) CHECK FINE>=0 AND<=200)
SAT 2 (SIMPLE SELECT, ORDER BY)
1. SELECT * FROM STUDENT;
2. SELECT NAME FROM STUDENT;
3. SELECT NAME, SECTION FROM STUDENT;
4. SELECT NAME, FEE FROM STUDENT;
5. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT;
6. SELECT NAME, FEE, AGE FROM STUDENT;
7. SELECT * FROM STUDENT ORDER BY ROLLNO ;
8. SELECT * FROM STUDENT ORDER BY ROLLNO DESC;
9. SELECT * FROM STUDENT WHERE AGE IS NULL;
10. SELECT * FROM STUDENT WHERE AGE NOT NULL;
SAT 3 (SELECT WITH COUNT)
1. SELECT COUNT(*) FROM STUDENT;
2. SELECT COUNT(NAME) FROM STUDENT;
3. SELECT COUNT(AGE) FROM STUDENT;
4. SELECT COUNT(FEE) FROM STUDENT;
5. SELECT COUNT(CLASS) FROM STUDENT;

Page 39 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

6. SELECT COUNT(SECTION) FROM STUDENT;

SAT 4 (SELECT WITH COUNT AND DISTINCT)


1. SELECT * FROM STUDENT;
2. SELECT COUNT(*) FROM STUDENT;
3. SELECT DISTINCT AGE FROM STUDENT;
4. SELECT ALL AGE FROM STUDENT;
5. SELECT COUNT(DISTINCT CLASS) FROM STUDENT;
6. SELECT COUNT(DISTINCT SECTION) FROM STUDENT;
7. SELECT COUNT(DISTINCT AGE) FROM STUDENT;
SAT 5 (SELECT WITH COUNT AND GROUP BY)
1. SELECT * FROM STUDENT;
2. SELECT COUNT(*) FROM STUDENT GROUP BY CLASS;
3. SELECT CLASS, COUNT(*) FROM STUDENT GROUP BY CLASS;
4. SELECT SECTION, COUNT(*) FROM STUDENT GROUP BY SECTION;
5. SELECT AGE, COUNT(*) FROM STUDENT GROUP BY AGE;
6. SELECT CLASS, SUM(FEE) FROM STUDENT GROUP BY CLASS;
7. SELECT CLASS, MIN(FEE),MAX(FEE) FROM STUDENT GROUP BY CLASS;
8. SELECT SECTION, MIN(FEE),MAX(FEE) ,SUM(FEE) FROM STUDENT GROUP BY SECTION;
SAT 6 (SELECT WITH COUNT AND GROUP BY+ HAVING)
1. SELECT * FROM STUDENT;
2. SELECT COUNT(*) FROM STUDENT;
3. SELECT CLASS, COUNT(*) FROM STUDENT GROUP BY CLASS;
4. SELECT CLASS, COUNT(*) FROM STUDENT GROUP BY CLASS HAVING COUNT(*)>2;
5. SELECT SECTION, COUNT(*) FROM STUDENT GROUP BY SECTION HAVING COUNT(*)<2;
6. SELECT FEE, SUM(FEE) FROM STUDENT GROUP BY AGE HAVING COUNT(*)>=2;
7. SELECT FEE, AVG (FEE) FROM STUDENT GROUP BY AGE HAVING COUNT(*)<>2; //!=
SAT 7 (SELECT WITH WHERE, BETWEEN, IN NOT IN)
1. SELECT * FROM STUDENT;
2. SELECT * FROM STUDENT WHERE AGE <14;
3. SELECT * FROM STUDENT WHERE FEE >3000;
4. SELECT * FROM STUDENT WHERE ROLLNO >20;
5. SELECT * FROM STUDENT WHERE ROLLNO <20;
6. SELECT NAME, SECTION FROM STUDENT WHERE FEE >3000;
7. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT WHERE AGE >12 AND AGE<15;
8. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT WHERE AGE BETWEEN 12 AND 15;
9. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT WHERE AGE =12 OR AGE=15 OR AGE=9;
10. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT WHERE AGE IN(12 ,15 ,9);
11. SELECT NAME, AGE, FEE, ROLLNO FROM STUDENT WHERE AGE NOT IN(12 ,15 ,9);
12. SELECT NAME, AGE, FEE, FEE*12 “ANNUAL” FROM STUDENT WHERE AGE >12;
SAT 8 (SELECT WITH WHERE + LIKE)
1. SELECT * FROM STUDENT;
2. SELECT * FROM STUDENT WHERE NAME LIKE “A%”
3. SELECT * FROM STUDENT WHERE NAME LIKE “a%”
4. SELECT * FROM STUDENT WHERE NAME LIKE “%E”
5. SELECT * FROM STUDENT WHERE NAME LIKE “%A%”
6. SELECT * FROM STUDENT WHERE AGE LIKE “1%”
7. SELECT * FROM STUDENT WHERE AGE LIKE “2%”
8. SELECT * FROM STUDENT WHERE AGE LIKE “%2”
9. SELECT * FROM STUDENT WHERE NAME LIKE “%_ _M”
10. SELECT * FROM STUDENT WHERE NAME LIKE “M _ %”

Page 40 of 41 EDUCATION FOR EVERYONE


DoyPyEdu PLAY WITH PYTHON

11. SELECT * FROM STUDENT WHERE NAME LIKE “%_ _ _ _”


12. SELECT * FROM STUDENT WHERE FEE LIKE “%9”
13. SELECT * FROM STUDENT WHERE FEE LIKE “3%”
14. SELECT NAME, AGE, FEE FROM STUDENT WHERE FEE LIKE “%2%”
SAT 9 (ALTER COMMAND)
1. ALTER TABLE STUDENT ADD PHONE INT(12) ;
2. ALTER TABLE STUDENT ADD ADMNO INT(5);
3. ALTER TABLE STUDENT MODIFY PHONE CHAR(12) ;
4. ALTER TABLE STUDENT MODIFY (ADMNO CHAR(7));
5. ALTER TABLE STUDENT ADD DOB DATE;
6. ALTER TABLE STUDENT DROP DOB;
SAT 10 (UPDATE COMMAND)
1. UPDATE STUDENT SET FEE = FEE + FEE * 0.05;
2. UPDATE STUDENT SET FEE = FEE + 55;
3. UPDATE STUDENT SET FEE = FEE + 500 WHERE CLASS=10;
4. UPDATE STUDENT SET AGE = AGE + 1 WHERE AGE>12;
5. UPDATE STUDENT SET AGE = AGE + 2 WHERE AGE<>15;
6. UPDATE STUDENT SET AGE = AGE + 2 WHERE AGE<>15 AND AGE<>16;
7. UPDATE STUDENT SET AGE = AGE - 1 WHERE AGE IN (10,13,14,18);
8. UPDATE STUDENT SET AGE = AGE - 1 WHERE AGE NOT IN (11,13,15);
SAT 11 (DELETE/DROP COMMAND)
1. DELETE FROM STUDENT ;
2. DELETE FROM STUDENT WHERE FEE >3000 ;
3. DELETE FROM STUDENT WHERE FEE <3000 ;
4. DELETE FROM STUDENT WHERE FEE >2900 AND FEE<=3000 ;
5. DELETE FROM STUDENT WHERE FEE =2900 OR FEE=3000 ;
6. DELETE FROM STUDENT WHERE FEE IN(2510,3410 ,2230,1509,3450);
7. DELETE FROM STUDENT WHERE FEE NOT IN(2510,3410 ,2230,1509,3450);
8. DELETE FROM STUDENT WHERE AGE>14 ;
9. DROP TABLE STUDENT;
SAT 12 (JOIN TABLE)
1. SELECT * FROM STUDENT, LIBRARY ;
2. SELECT * FROM STUDENT, LIBRARY WHERE STUDENT.ROLLNO= LIBRARY.ROLLNO ;
3. SELECT * FROM STUDENT S, LIBRARY L WHERE S.ROLLNO= L.ROLLNO ;
4. SELECT ROLLNO,NAME,CLASS,SECTION, FINE FROM STUDENT S, LIBRARY L WHERE
S.ROLLNO= L.ROLLNO ;
5. SELECT ROLLNO,NAME,CLASS,SECTION, FINE FROM STUDENT S, LIBRARY L WHERE
S.ROLLNO= L.ROLLNO AND S.AGE>15;
6. SELECT ROLLNO,NAME,CLASS,SECTION, FINE FROM STUDENT S, LIBRARY L WHERE
S.ROLLNO= L.ROLLNO AND S.AGE IN (10,13,15);
7. SELECT S.ROLLNO,S.NAME, S.CLASS, S.SECTION, L.FINE FROM STUDENT S, LIBRARY L
WHERE S.ROLLNO= L.ROLLNO AND S.AGE IN (10,13,15);
8. SELECT ROLLNO,NAME,CLASS,SECTION, FINE FROM STUDENT S, LIBRARY L WHERE
S.ROLLNO= L.ROLLNO AND L.FINE>40 AND S.AGE<16;
SAT 13 (INSERT DATA IN TABLE)
1. INSERT INTO STUDENT VALUES(01 ,”DEEPAK” ,10, “A”, 12, 2301);
01 DEEPAK 10 A 12 2301
2. INSERT INTO STUDENT(ROLLNO,NAME,CLASS,SECTION,FEE)
VALUES (20, HARISH, 10 ,D, 1020);
20 HARISH 10 D NULL 1020

Page 41 of 41 EDUCATION FOR EVERYONE

You might also like