0% found this document useful (0 votes)
7 views

Python_Exam_Version2

The document outlines a Python Programming Exam consisting of five sections: Theory Questions, Code Snippet Completion, Code Dry Runs, Code Error Correction, and Application-Based Coding, totaling 100 marks. Each section tests different skills, including theoretical knowledge, code completion, prediction of code outputs, error correction, and practical coding applications. The exam covers key Python concepts such as typing, execution methods, variable scope, and the use of libraries.

Uploaded by

nisssrine
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)
7 views

Python_Exam_Version2

The document outlines a Python Programming Exam consisting of five sections: Theory Questions, Code Snippet Completion, Code Dry Runs, Code Error Correction, and Application-Based Coding, totaling 100 marks. Each section tests different skills, including theoretical knowledge, code completion, prediction of code outputs, error correction, and practical coding applications. The exam covers key Python concepts such as typing, execution methods, variable scope, and the use of libraries.

Uploaded by

nisssrine
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
You are on page 1/ 2

Python Programming Exam - Version 2

Section 1: Theory Questions (20 marks)


1. Explain the differences between dynamically-typed and statically-typed languages.
2. What are Python?s execution methods? Give an example for each.
3. What is the significance of indentation in Python?
4. Define and explain the purpose of docstrings in Python functions.
5. Differentiate between local and global variables in Python.
6. What are the advantages of using external Python libraries such as NumPy and Pandas?
7. Explain how inheritance and polymorphism are used in Object-Oriented Programming.

Section 2: Code Snippet Completion (20 marks)


1. Complete the function that checks if a number is prime:
def is_prime(n):
if n < ____:
return False
for i in range(2, ____):
if n % i == 0:
return False
return True
2. Complete the function that reverses a string:
def reverse_string(s):
return s[____:____]
3. Fill in the missing code in the factorial function:
def factorial(n):
if n == 0:
return ____
return ____ * factorial(n - 1)

Section 3: Code Dry Runs (20 marks)


1. Predict the output of the following:
x = [1, 2, 3]
y = x[:]
y.append(5)
print(x)
print(y)
2. Predict the output:
def modify_string(s):
s += ' World'
string = 'Hello'
modify_string(string)
print(string)

Section 4: Code Error Correction (20 marks)


1. Fix the syntax and logical errors:
def multiply(a, b)
return a * b
print(multiply(2, 3))
2. Fix the IndexError:
numbers = [5, 10, 15]
print(numbers[3])

Section 5: Application-Based Coding (20 marks)


1. Write a function `count_vowels(s: str) -> int` that counts the number of vowels in a given string.
def count_vowels(s):
# Your code here
2. Write a function `merge_sorted_lists(list1, list2)` that merges two sorted lists into one sorted list.
def merge_sorted_lists(list1, list2):
# Your code here

You might also like