Ap Cat Marking
Ap Cat Marking
b) Using a relevant Python code snippet, differentiate between the arithmetic operators
in Python: %, / and // (3 Marks)
i. % (Modulus Operator):
The floor division operator // also performs division but rounds down the result to the
nearest whole number (integer division). It discards the decimal part.
Each correct explanation earns two marks with a correct code snippet earns two
marks.
c) Explain the difference between a local variable and a global variable (2 Marks)
• Global variables are defined at the top level of a Python script or module and can
be accessed from any part of the code.
• Local variables are defined within a function's scope and are only accessible within
that function. They are created when the function is called and destroyed when the
function exits.
Correct code with proper explanation earns full marks
d) What are Python data types? Provide examples of at least three different data types with
their respective initialization (3 Marks)
Integer (int):
• An integer data type represents whole numbers, both positive and negative, without
any decimal point.
Float (float):
• A float data type represents floating-point numbers, which can have decimal points
and fractions.
String (str):
• A string data type represents a sequence of characters enclosed in single (' '),
double (" "), or triple (''' ''' or """ """) quotes.
Correct code with proper explanation earns one mark for each
f) Given the following Python Code snippet. Answer the following questions:
i. What will be the data type of x for the following code? (1 Mark)
string
ii. Write a python code to print out the data type of x (1 Mark)
print(type(x))
iii. Write a python code to compare the variable type to the integer data type
(1 Mark)
(isinstance(x, int)
Each correct answer earns one mark
g) Write a Python program to read a value from the keyboard and output the phrase
NEGATIVE if the number is negative, POSITIVE if the number is positive or ZERO
otherwise. (4 Marks)
i) How do you comment out code in Python, and why is commenting important? Using
relevant code snippet, show two ways you can comment out Python code (4 Marks)
Comments are placed using either # or “”” “””