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

Year 8 Python Coding Exam 2025

Uploaded by

Samuel Oppong
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)
11 views3 pages

Year 8 Python Coding Exam 2025

Uploaded by

Samuel Oppong
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

HAPPY KIDS SCHOOL

END OF YEAR EXAMINATION 2025


SUBJECT: CODING
CLASS: YEAR 8 DURATION: 2 HOURS

NAME: …….…………………………………………………………… DATE: ………..………………….


CODING: PYTHON (GAME DEVELOPMENT)
SECTION A

1. What is the correct way to create an array in 7. How do you import a module in Python?
Python? A) include module_name
A) arr = array('i', [1, 2, 3]) B) import module_name
B) arr = [1, 2, 3] C) using module_name
C) arr = {1, 2, 3} D) require module_name
D) arr = (1, 2, 3)
8. What is the correct syntax for an if statement in
2. How do you access the third element in an array Python?
arr? A) if (condition) {
A) arr[3] B) if condition:
B) arr[2] C) if condition then:
C) arr[1] D) if (condition):
D) arr[0]
9. How do you write an if...else statement in
3. How do you change the value of the second Python?
element in an array arr to 5? A) if condition: else:
A) arr[1] = 5 B) if condition then else
B) arr[2] = 5 C) if condition: else
C) arr[0] = 5 D) if condition: else:
D) arr[3] = 5
10. Which of the following can be used to check
4. How do you define a function in Python? multiple conditions?
A) def functionName(): A) else if
B) function functionName(): B) elif
C) define functionName(): C) elseif
D) function functionName{}: D) else if:

5. How do you call a function named 11. What is the output of the following code:
myFunction?
A) call myFunction() x=5
B) myFunction if x > 10:
C) myFunction() print("Greater")
D) call myFunction else:
print("Smaller or Equal")
6. How do you pass arguments to a function?
A) def myFunction(args): A) Greater
B) def myFunction(arg1, arg2): B) Smaller
C) myFunction(arg1, arg2) C) Smaller or Equal
D) Both B and C D) Equal
12. Which of the following statements will 16. Which operator is used for equality
execute the else block? comparison?
x=3 A) ==
if x > 5: B) =
print("x is greater than 5") C) ===
else: D) equals
print("x is 5 or less")
17. Which operator is used to assign a value to a
A) x = 6 variable?
B) x = 5 A) ==
C) x = 4 B) =
D) Both B and C C) +=
D) ->
13. What is the correct syntax for a while loop in
Python? 18. How do you pass arguments to a function?
A) while condition { A) def myFunction(args):
B) while condition: B) def myFunction(arg1, arg2):
C) while (condition): C) myFunction(arg1, arg2)
D) while (condition) D) Both B and C

14. What is the output of the following code: 19. What is the output of len([1, 2, 3]) in Python?
i=1 A) 2
while i < 5: B) 3
print(i) C) 4
i += 1 D) 5

A) 1 2 3 4 5 20. How do you access the first element of a list in


B) 1 2 3 4 Python?
C) 1 2 3 A) list[0]
D) 1 2 3 4 5 6 B) list[1]
C) list[First]
15. What will be the output of the following code? D)list[0,1]
x = 10
while x > 5:
print(x)
x -= 2
A) 10 8 6 4
B) 10 8 6
C) 10 9 8 7 6
D) 10 8 6 4 2
SECTION B
Answer 2 questions. Question 1 and any other one.

1.) Below is the code for a text based game written with the Python programming language.
Explain the codes, line-by-line:

import random

def number_guessing_game():
number_to_guess = [Link](1, 100)
guess = None
attempts = 0

print("Welcome to the Number Guessing Game!")


print("I have selected a number between 1 and 100. Can you guess it?")

while guess != number_to_guess:


guess = int(input("Enter your guess: "))
attempts += 1

if guess < number_to_guess:


print("Too low!")
elif guess > number_to_guess:
print("Too high!")

print("Congratulations! You guessed the number in “ + str(attempts) + " attempts.")

number_guessing_game()

2. a.) Create a python function that accepts two numbers from a user and computes its sum. Call
this function and pass 3, 70 to it. What is the output of this program?

b.) Explain the difference between if, elif, and else statements.

3. a.) Write a Python program to check if a number is positive, negative, or zero.


b.) Explain the purpose of indentation in Python.

You might also like