All Important Questions in Python For o Level Exam
All Important Questions in Python For o Level Exam
O-Level (M3-R5)
Python Important
Questions for O-Level
Video Tutorial
O-Level M3-R5 Full Video
Playlist Available on
YouTube Channel UPCISS
1
Website For Free PDF Notes: www.upcissyoutube.com
2
Website For Free PDF Notes: www.upcissyoutube.com
num = 12345
result = sum_of_digit(num)
print("Sum of digits in",num,"is", result)
Output:
Sum of digits in 12345 is 15
3
Website For Free PDF Notes: www.upcissyoutube.com
for i in test_str:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
A = [ [1, 1, 1],
[2, 2, 2]]
B = [[0,0],[0,0],[0,0]]
transpose(A, B)
Output:
Result matrix is
1 2
1 2
1 2
4
Website For Free PDF Notes: www.upcissyoutube.com
f = open('myfile.txt','r')
st= f.read()
count_str(st)
f.close()
Output:
myfile.txt content
Alphabets: 28 1 Hello Students
Lowercase: 19 2 Welcome to UPCISS
Uppercase: 9 3 4502
Digits: 7
Words: 9
8. Take two NumPy arrays having two dimensions.
Concatenate the arrays on axis 1.
Program:
import numpy as np
arr1 = np.arange(1,10).reshape(3,3)
arr2 = np.arange(10,19).reshape(3,3)
print(arr1,'\n')
print(arr2,'\n')
arrcon = np.concatenate((arr1,arr2),axis=1)
print(arrcon)
5
Website For Free PDF Notes: www.upcissyoutube.com
Output:
[[1 2 3]
[4 5 6]
[7 8 9]]
[[10 11 12]
[13 14 15]
[16 17 18]]
[[ 1 2 3 10 11 12]
[ 4 5 6 13 14 15]
[ 7 8 9 16 17 18]]
6
Website For Free PDF Notes: www.upcissyoutube.com
7
Website For Free PDF Notes: www.upcissyoutube.com
arr = [10, 50, 30, 70, 80, 60, 20, 90, 40]
x = 20
n = len(arr)
result = linear_search(arr, n, x)
if(result == -1):
print("Element is not present in array")
else:
print("Element is present at index", result)
Output:
Element is present at index 6
8
Website For Free PDF Notes: www.upcissyoutube.com
Binary Search ,d searching algorithm gS tks array dks ckj ckj vk/ks
esa foHkkftr djds element dks search djrk gSA binary search ges’kk
,d sorted array ds lkFk fd;k tkrk gSA ;g Linear search dh vis{kk
de le; yxkrk gSA
# Program for Binary Search
arr = [2,5,8,12,16,23,38,56,72,91]
x = 23
result = binary_search(arr, x)
if(result == -1):
print("Element is not present in array")
else:
print("Element is present at index", result)
Output:
Element is present at index 5
9
Website For Free PDF Notes: www.upcissyoutube.com
16. Illustrate the LEGB rules and its significance with help of
suitable diagram.
Program ds varxZr gj name reference ds fy, vFkkZr tks vki fdlh
function ;k program ls variable dks access djrs gSa rks python gesa’kk
name resolution rule dks viukrk gS ftls LEGB rule dgrs gSaA
Local(L): Defined inside function/class
Enclosed(E): Defined inside enclosing functions(Nested function concept)
Global(G): Defined at the uppermost level
Built-in(B): Reserved names in Python built-in modules
10
Website For Free PDF Notes: www.upcissyoutube.com
It takes a lot of hard work to make notes, so if you can pay some fee 50, 100,
200 rupees which you think is reasonable, if you are able to Thank you...
नोट् स बनाने में बहुत मेहनत लगी है , इसललए यलि आप कुछ शुल्क 50,100, 200 रूपए जो
आपको उलित लगता है pay कर सकते है , अगर आप सक्षम है तो, धन्यवाि ।
11