0% found this document useful (0 votes)
11 views7 pages

Revision Test Python

The document is a revision test for Grade VIII students focusing on Python programming, consisting of multiple questions that require finding outputs of given code snippets and writing a program for a seating arrangement. Each question includes code examples and expected outputs with explanations. The test is structured to assess students' understanding of basic Python operations, loops, and logical expressions.
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)
11 views7 pages

Revision Test Python

The document is a revision test for Grade VIII students focusing on Python programming, consisting of multiple questions that require finding outputs of given code snippets and writing a program for a seating arrangement. Each question includes code examples and expected outputs with explanations. The test is structured to assess students' understanding of basic Python operations, loops, and logical expressions.
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
You are on page 1/ 7

HIS-CIS GRADE VIII AC-YR 2024-25

REVISION TEST- PYTHON [TOTAL:35 MARKS]

1. Find the output of: [2 X 10 =20]

a. x = 20

y=7

Num = (x // y) + 2

print(Num)

b. x = True

y = False

z=True

answer = x or y or z

print(answer)

c. x = 5

y=3

z=x*y

print(z)

d. x = True

y = False

z = not (x and y)

print(z)

e. a = 8

b=2

c=a/b+a%b

print(c)
HIS-CIS GRADE VIII AC-YR 2024-25

f. p = 15

q=4

r = (p // q) * (p % q) + 5

print(r)

g. m = 3

n=2

result = (m ** n) - (m * n) + (m // n)

print(result)

h. x = 12

y=5

z = (x % y) * (x // y) - x + y

print(z)

i. a = 10

b=3

c = (a // b) + (a % b) * (b ** 2)

print(c)

j. x=7

y=2

z = (x * y) - (x // y) + (x % y)

print(z)
HIS-CIS GRADE VIII AC-YR 2024-25

2. What is the output of the following Python code? [5X2=10]

a. for i in range(1, 6):

j=1

while j <= i:

print("*", end=" ")

j += 1

print()

b. for i in range(1, 6):


num = 1
while num <= i:
print(num, end=" ")
num += 1
print()

3. A teacher is organizing a seating arrangement for students in an auditorium. The first


row has 5 students, the second row has 4 students, the third row has 3 students, and so
on until the last row has only 1 student.

Write a Python program that simulates this seating arrangement using two loops: [5]

 The outer loop should represent the rows.


 The inner loop should print the number of students in each row in decreasing
order.

ANSWERS

1. Output of the following Python code:

a.

x = 20
y = 7
Num = (x // y) + 2
print(Num)
HIS-CIS GRADE VIII AC-YR 2024-25

Output: 4
Explanation: x // y performs integer division (20 divided by 7 gives 2), and then 2 + 2 gives
4.

b.

x = True
y = False
z = True
answer = x or y or z
print(answer)

Output: True
Explanation: The or operator returns True if any operand is True. Since x and z are True, the
result is True.

c.

x = 5
y = 3
z = x * y
print(z)

Output: 15
Explanation: The multiplication of 5 and 3 results in 15.

d.

x = True
y = False
z = not (x and y)
print(z)

Output: True
Explanation: x and y is False, so not (False) becomes True.
HIS-CIS GRADE VIII AC-YR 2024-25

e.

a = 8
b = 2
c = a / b + a % b
print(c)

Output: 6.0
Explanation: a / b is 4.0, and a % b is 0. So, 4.0 + 0 = 4.0.

f.

p = 15
q = 4
r = (p // q) * (p % q) + 5
print(r)

Output: 20
Explanation: (p // q) is 3, and (p % q) is 3. So, (3 * 3) + 5 = 9 + 5 = 20.

g.

m = 3
n = 2
result = (m ** n) - (m * n) + (m // n)
print(result)

Output: 1
Explanation: m ** n is 9, m * n is 6, and m // n is 1. So, 9 - 6 + 1 = 1.

h.

x = 12
y = 5
z = (x % y) * (x // y) - x + y
print(z)

Output: -2
Explanation: x % y is 2, x // y is 2. So, 2 * 2 - 12 + 5 = 4 - 12 + 5 = -2.
HIS-CIS GRADE VIII AC-YR 2024-25

i.

a = 10
b = 3
c = (a // b) + (a % b) * (b ** 2)
print(c)

Output: 19
Explanation: a // b is 3, a % b is 1, and b ** 2 is 9. So, 3 + (1 * 9) = 3 + 9 = 19.

j.

x = 7
y = 2
z = (x * y) - (x // y) + (x % y)
print(z)

Output: 10
Explanation: x * y is 14, x // y is 3, and x % y is 1. So, 14 - 3 + 1 = 12.

2. Output of the following Python code:

a.

for i in range(1, 6):


j = 1
while j <= i:
print("*", end=" ")
j += 1
print()

Output:

*
* *
* * *
* * * *
* * * * *

Explanation: The outer loop runs from 1 to 5, and the inner loop prints stars (*) as per the value
of i.
HIS-CIS GRADE VIII AC-YR 2024-25

b.

for i in range(1, 6):


num = 1
while num <= i:
print(num, end=" ")
num += 1
print()

Output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Explanation: The outer loop runs from 1 to 5, and the inner loop prints numbers starting from 1
up to i.

3. Python program for the seating arrangement:


# Outer loop represents rows
for i in range(5, 0, -1):
# Inner loop prints the number of students in each row
for j in range(i):
print("*", end=" ")
print()

Explanation: The outer loop starts from 5 (first row) and goes down to 1 (last row), and the
inner loop prints * for the number of students in each row. The result will show a seating
arrangement where the first row has 5 students, the second row has 4, and so on.

Output:

* * * * *
* * * *
* * *
* *
*

You might also like