0% found this document useful (0 votes)
15 views8 pages

Solved Paper

The document contains a series of programming questions and exercises related to Python, including output-based questions, short programming tasks, and data handling with Pandas. It covers topics such as list and dictionary manipulation, matrix addition, and group operations in DataFrames. Additionally, it discusses iterative operations and nested loops with examples.

Uploaded by

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

Solved Paper

The document contains a series of programming questions and exercises related to Python, including output-based questions, short programming tasks, and data handling with Pandas. It covers topics such as list and dictionary manipulation, matrix addition, and group operations in DataFrames. Additionally, it discusses iterative operations and nested loops with examples.

Uploaded by

Satbharai Sethar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

🔹 Section A: Output Based Questions

(5 × 3 = 15 Marks)
👉 Har question ka exact output likhein.

Q1.

x = [1, 2, 3]

y=x

[Link](4)

print(x)

Answer: [1,2,3]

Q2.

t = (10, [20, 30], 40)

t[1][0] = 99

print(t)

Answer: (10, [99,30],40)

Q3.

s = "MastersPython"

print(s[3:10:2])

Answer: trPt

Q4.

data = [(1, "Ali"), (2, "Sara"), (3, "Usman")]

for i in data:

print(i[1])

Answe:
“Ali”

“Sara”

“Usman”

Q5.

d = {"a":1, "b":2}

for k in d:

d[k] += 5

print(d)

Answer:

🔹 Section B: Short Programming Questions

(4 × 5 = 20 Marks)
👉 Python code likhein.

Q6.

Ek program likhein jo 2×2 matrices ka addition perform kare.

a = [[1,2],[3,4]]

b = [[5,6],[7,8]]

c = [[0,0], [0,0]]

for i in range(len(a)):

for j in range(len(a[0])):

c[i][j] = a[i][j]+b[i][j]

for i in c:

print(i)
Q7.

Ek list di gayi hai:

L = [2, 5, 8, 11, 14]

👉 Sirf even numbers ka sum calculate karein.

L = [2, 5, 8, 11, 14]

even = 0

for i in L:

if i%2 == 0:

even += i

print(f"Sum = {even}")

Q8.

Ek dictionary di gayi hai:

students = {

"Ali": 85,

"Sara": 92,

"Usman": 78

👉 Highest marks aur student ka naam print karein.

Q9.

Ek tuple ke andar list hai:

T = (1, [3, 6, 9], 5)

👉 List ke tamam elements ko 2 se multiply kar dein aur updated tuple print
karein.

T = (1, [3, 6, 9], 5)


for i in range(len(T[1])):

T[1][i]= T[1][i] * 2

for i in range(len(T)):

print(T[i])

🔹 Section C: Pandas & Data Handling

(2 × 5 = 10 Marks)

Q10.

Neeche diya gaya DataFrame consider karein:

import pandas as pd

data = {

"Name": ["Ali", "Sara", "Ali", "Usman"],

"Marks": [80, 90, 85, 70]

import pandas as pd

data = {

"Name": ["Ali", "Sara", "Ali", "Usman"],

"Marks": [80, 90, 85, 70]

df = [Link](data)

[Link]()

g = [Link]("Name")

g.get_group("Ali")

[Link]()

df = [Link](data)
(a) groupby use kar ke Ali ke average marks find karein.
(b) Output likhein.

Q11.

Pandas ka use kar ke:

 DataFrame banayein

 head() function ka kaam explain karein

 Example ke sath

import pandas as pd

data = {
"id": ["s1", "s2", "s3", "s4"],
"name": ["Satbharai", "Aqsa", "fatima", "Safia"],
"marks": [90, 80, 70, 60],
"city": ["chakwal", "mehrabpur", "chakwal", "mehrabpur"]
}
df = [Link](data)
[Link]()
# [Link]() basically shows the top 5 rows of the data stored in data
frame

🔹 Section D: Long / Logical Questions

(2 × 5 = 10 Marks)

Q12.

Python me structures within structures explain karein.


👉 Example dein:

 list inside tuple

 dictionary inside list


👉 Accessing aur printing bhi show karein.

# if structures like tuple or list or dictionaries are user within


another structures this phenomenon is called use of structures within
another structure
#for Example list inside touple
T = (1,2,[4,5,6],)
T[2][0] = 100
T
#tuples are immutable but lists inside tuple are mutable
#for Example: Dictionaries inside lists
L = [1,2,{"h": "Haris"}]
[Link](4)
[Link](4)
[Link](0, 12)
L[3]["h"]

Q13.

Python me iterative operations kya hoti hain?

The iterative operations are the operation that are repeated certain no of
times or till a certain situation occurs or condition fulfills.

For example: printing sum to n numbers, calculating factorial etc


👉 for aur while loops ko example ke sath explain karein.

For loop is the loop that is most common initialization condition check and
increment occurs within the loop. After that full collon is inserted and with
indentation centain statement is run iteratively.

For Example:

L = [1,2,3,4,5]

for i in L:

print(i)

While Loop:

Initialization before loop condition check in loop -> full collon -> statement
execution -> increament.

L = [1,2,3,4,5]

i =0

while i<5:

print(L[i])

i+=1
👉 Nested loop ka bhi example dein.

Nested loops are loops used inside a loop. For example when we deal with
matrix addition and multiplication of matrices etc

l1 = [[1,4,3],

[1,9,3],

[2,2,3]]

l2 = [[2,3,4],

[2,3,4],

[2,3,4]]

l3 = [[0,0,0],

[0,0,0],

[0,0,0]]

for i in range(len(l1)):

for j in range(len(l2[0])):

for k in range(len(l2)):

l3[i][j] += l1[i][k] * l2[k][j]

for row in l3:

print(row)

🎯 Important Notes (Exam Focus)

✔ Loops + nested structures


✔ Output prediction
✔ Pandas basics
✔ Logic clarity

You might also like