0% found this document useful (0 votes)
543 views12 pages

All Important Questions in Python For o Level Exam

Uploaded by

Abhijay Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
543 views12 pages

All Important Questions in Python For o Level Exam

Uploaded by

Abhijay Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UPCISS

O-Level (M3-R5)
Python Important
Questions for O-Level

Video Tutorial
O-Level M3-R5 Full Video
Playlist Available on
YouTube Channel UPCISS

Free Online Computer Classes on


YouTube Channel UPCISS
www.youtube.com/upciss
For free PDF Notes
Our Website: www.upcissyoutube.com

Copyright © 2022 UPCISS


Website For Free PDF Notes: www.upcissyoutube.com

1. Explain the role of linker and loader in compilation.


2. What is a NumPy array? How they are different from lists?
3. Write a flowchart that finds the sum of series:
4. Write a recursive function to find the sum of digits of a number.
5. Write a program that takes a sentence as input from the user and
returns the frequency of each letter .Use a variable of dictionary type
to maintain the count.
6. Take an array of 2 rows and three columns, populate it and find the
transpose.
7. Write a function that reads the contents of the file myfile.txt and
counts the number of alphabets, lowercase letters, uppercase
letters, digits and number of words.
8. Take two NumPy arrays having two dimensions. Concatenate the
arrays on axis 1.
9. Write a Python program to get the smallest number from a list.
10. Write a NumPy program to convert a Python dictionary to a NumPy
ndarray.
11. Write a program code to open a data file save element values
2,4,9,10,11 in this data file and print these data values by accessing
the file.
12. Write the basic steps required by the interpreter to execute a python
program.
13. How memory is managed in Python? Give the tools name that help
to find bugs or perform static analysis?
14. Define mutable and immutable data type.
15. Explain the concept of Linear and Binary search with Python
program.
16. Illustrate the LEGB rules and its significance with help of suitable
diagram.

1
Website For Free PDF Notes: www.upcissyoutube.com

1. Explain the role of linker and loader in compilation.


Linker: ;g ,d Special program gS tks Compiler ;k Assembler
}kjk Generate object files ds VqdM+ksa dks tksM+dj ds ,d Executable
file cukrk gS (.exe file). Object files esa linker file ds Execution ds
fy, vko’;d lHkh Libraries dks Search djds tksM+us dk dke djrk gSA
;g nks ;k nks ls vf/kd object program dks Merge djrk gS vkSj muds
chp ,d link cukrk gSA
Loader: ;g ,d Special program gS tks linker ls Executable file
dks input ysrk gS vkSj mls main memory esa load djrk gS] vkSj
computer }kjk execution ds fy, bls rS;kj djrk gSA

2. What is a NumPy array? How they are different from lists?


NumPy: NumPy python esa scientific calculation ds fy, ,d cgqr gh
vPNk package gSA NumPy array cM+h la[;k esa data ij advance
mathematical vkSj vU; izdkj ds operations djus dh lqfo/kk iznku
djrk gSA NumPy dksbZ nwljh programming language ugha gS] cfYd ;g
,d python extension module gSA
NumPy List
Create NumPy array numpy.array() Create List L1 = [ ]
by default Homogeneous Homogeneous or heterogeneous.
Element wise operation is possible Element wise operation is not
possible
Low Memory consumption High Memory consumption
Fast computing Slow computing

2
Website For Free PDF Notes: www.upcissyoutube.com

3. Write a flowchart that finds the sum of series:


s=1 + x/1 + x^2/2 + x^3/3 + .. upto n terms?
Flowchart:

4. Write a recursive function to find the sum of digits of a


number.
Program:
def sum_of_digit( n ):
if n == 0:
return 0
return (n % 10 + sum_of_digit(int(n / 10)))

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

5. Write a program that takes a sentence as input from the


user and returns the frequency of each letter .Use a
variable of dictionary type to maintain the count.
Program:
test_str = "UPCISS"
all_freq = {}

for i in test_str:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1

print ("Count of all characters ",all_freq)


Output:
Count of all characters {'U': 1, 'P': 1, 'C': 1, 'I': 1, 'S': 2}
6. Take an array of 2 rows and three columns, populate it and
find the transpose.
Program:
def transpose(A, B):
for i in range(3):
for j in range(2):
B[i][j] = A[j][i]

A = [ [1, 1, 1],
[2, 2, 2]]

B = [[0,0],[0,0],[0,0]]
transpose(A, B)

print("Result matrix is")


for i in range(3):
for j in range(2):
print(B[i][j], " ", end='')
print()

Output:
Result matrix is
1 2
1 2
1 2

4
Website For Free PDF Notes: www.upcissyoutube.com

7. Write a function that reads the contents of the file


myfile.txt and counts the number of alphabets, lowercase
letters, uppercase letters, digits and number of words.
Program:
def count_str(st):
alpha=low=upp=digit=0
word=1
for i in st:
if i.isalpha():
alpha+=1
if i.islower():
low+=1
else:
upp+=1
elif i.isdigit():
digit+=1
elif i.isspace():
word+=1
print('Alphabets:',alpha)
print('Lowercase:',low)
print('Uppercase:',upp)
print('Digits:',digit)
print('Words:',word)

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]]

9. Write a Python program to get the smallest number from a


list.
Program:
li=[2,6,5,1,4]
small=li[0]
for i in li:
if small > i:
small=i
print(small)
Output: 1

10. Write a NumPy program to convert a Python dictionary


to a NumPy ndarray.
Program:
import numpy as np
dict = {0: 3, 1: 1, 2: 8, 3: 5}
nd_array = np.array(list(dict.items()))
print(nd_array)
Output:
[[0 3]
[1 1]
[2 8]
[3 5]]

6
Website For Free PDF Notes: www.upcissyoutube.com

11. Write a program code to open a data file save element


values 2,4,9,10,11 in this data file and print these data
values by accessing the file.
Program:
f = open('data.txt','r+')
f.write('2491011')
f.seek(0)
print(f.read())
f.close()
Output:
2491011
12. Write the basic steps required by the interpreter to
execute a python program.
Follow the steps written below.
 Make a text file and save it with the name of your choice with an extension . py.
 Write the code to print hello world in the .py file and save your file.
 Open command prompt.
 Run the command – python filename.py.

13. How memory is managed in Python? Give the tools


name that help to find bugs or perform static analysis?
tSlk fd ge tkurs gSa] Python dynamic memory allocation dks
mi;ksx djrk gS ftls Heap data structure manage djrk gSA
Memory Heap mu object vkSj vU; data structure dks j[krk gS
ftudk mi;ksx izksxzke esa fd;k tk,xkA
PyChecker vkSj Pylint static analysis tool gSa tks Python esa bugs
[kkstus esa help djrs gSaA
14. Define mutable and immutable data type.
Mutable: mutable data type esa ge object dh value dks change
dj ldrs gSaA List, Sets, Dictionaries ;s lc Mutable data type gSaA
Immutable: immutable data type esa ge object dh value dks
change ugh dj ldrs gSaA int, float, bool, str, tuple ;s lc
immutable data type gSaA

7
Website For Free PDF Notes: www.upcissyoutube.com

15. Explain the concept of Linear and Binary search with


Python program.
Linear Search simple approach dks follow djrk gS] tSls vxj gesa
fdlh array ls fdlh element dks search djuk gS] rks ge ml element
dks array ds lHkh element ds lkFk ,d&,d djds check djsaxs vkSj vxj
oks element gesa feyrk gS rks ge mls return dj nsaxsA linear search esa
Binary Search dh vis{kk le; T;knk yxrk gSA tSls%&
# Program for Linear Search (Sequential Search)
def linear_search(arr, n, x):
for i in range(0, n):
if (arr[i] == x):
return i
return -1

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

def binary_search(arr, x):


low, high = 0, len(arr)-1
while low <= high:
mid = (low + high) // 2
if x > arr[mid]:
low = mid + 1
elif x < arr[mid]:
high = mid - 1
else:
return mid
return -1

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

You might also like