Revision Test Python
Revision Test Python
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
j=1
while j <= i:
j += 1
print()
Write a Python program that simulates this seating arrangement using two loops: [5]
ANSWERS
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.
a.
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.
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.
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:
* * * * *
* * * *
* * *
* *
*