Font size
WorksheetsCS322 FINAL EXAMINATIONS
Total questions: 100
Worksheet time: 57mins
What is the primary function of a computer's CPU?
To run programs
To display graphics
To store data permanently
To connect to the internet
Which of the following is considered hardware?
Microsoft Word
RAM
Python
Adobe Photoshop
What does RAM stand for?
Random Access Memory
Read Access Memory
Read And Memory
Rapid Access Memory
Which of the following is an example of application software?
Word Processing Software
Device Drivers
Utility Programs
Operating System
What is the purpose of a program?
To manage memory
To connect hardware
To perform tasks as instructed
To store data
What is a byte composed of?
Sixteen bits
Two bits
Eight bits
Four bits
Which of the following is a type of secondary storage?
Motherboard
Hard Drive
CPU
RAM
What is the function of input devices?
To store data
To display output
To collect data
To process information
Which of the following is a programming language?
HTML
CSS
Python
XML
What does the fetch-decode-execute cycle refer to?
The process of executing a program
The process of storing data
The process of writing code
The process of debugging
What is the purpose of a flowchart in programming?
To execute commands
To store data
To write code
To visualize the program's logic
Which of the following is a characteristic of high-level programming languages?
They are machine-dependent
They are difficult to read
They are easier for humans to understand
They use mnemonics
What is the role of a compiler?
To execute code line by line
To manage memory
To translate high-level code into machine code
To debug programs
What is a variable in programming?
A fixed value
A name that represents a value
A type of loop
A function
What is the purpose of comments in code?
To increase performance
To store data
To execute commands
To document the code
What does the input function do in Python?
Executes code
Stores data
Reads user input
Displays output
Which of the following is a logical operator?
AND
ADD
MULTIPLY
SUBTRACT
What is a sentinel in programming?
A special value that marks the end of a sequence
A loop structure
A type of variable
A data type
What is the purpose of a while loop?
To repeat a block of code a specific number of times
To execute code once
To define a function
To repeat a block of code as long as a condition is true
What is the output of the following code: print(2 + 3)?
5
23
Error
None
Which of the following is a characteristic of a for loop?
It runs indefinitely
It requires a condition
It iterates a specific number of times
It cannot be nested
What is the purpose of the range function in Python?
To store data
To create a list of numbers
To execute a loop
To define a variable
What does the term 'input validation' refer to?
Executing commands
Checking if the input is correct before processing
Storing input data
Displaying output
What is a nested loop?
A loop inside another loop
A loop that executes once
A loop that runs indefinitely
A loop that does not execute
What is the correct syntax to define a function in Python?
function myFunction():
def myFunction:
def myFunction():
define myFunction():
What will be the output of the following code?
Hello, World!
Error
my_function
None
What is the correct syntax to call a function named myFunction?
call myFunction()
myFunction()
myFunction(call)
call myFunction
What does the following code output?
2
3
5
error
How can you return multiple values from a function?
By separating them with a comma
By using a list
By using a dictionary
All of the above
What is the output of the following code?
8
12
16
error
What does the following code output?
5
10
15
error
What is the term for a function that calls itself?
Loop function
Recursive function
Lambda function
Anonymous function
What is the output of the following code?
1
3
6
9
How do you specify default values for function parameters?
def func(x=10, y):
def func(x, y=10):
def func(x=10, y=10):
def func(x:10, y:10):
What will be the output of the following code?
7
12
34
error
What is the output of this code?
1
3
6
error
What is a lambda function in Python?
A function that can have any number of arguments
A function that can only have one argument
An anonymous function defined with the lambda keyword
A function that returns another function
What does the following code output?
5
10
15
error
How can you define a function with variable-length arguments?
def func(*args):
def func(*varargs):
def func(**args):
def func(varargs*):
What does the following code output?
{'a': 1, 'b': 2}
[1, 2]
(1, 2)
Error
What is the output of the following code?
5
6
32
error
What does the following code output?
2
3
-2
error
What will the following code output?
Hello from outer
Hello from inner
Error
None
What does the following code output?
9
11
13
error
print(Hello world!)
print("Hello world!" * 2)
people = ["John", "Rob", "Bob"]
print (people[-1])
what would this result be?
print(3*4+5)
Which of the following is the correct way to write a nested if statement?
What will be the output of the following code?
True
False
Error
None
What does the following code output if a = 3 and b = 5?
a is greater
a is equal to b
a is smaller
Error
What is the output of the following code?
True
False
Error
None
What does the following code output if 'y = 0'?
True
False
Error
None
What will the following code output if value = 100?
Non-zero value
Zero value
Error
None
What will the following code output if num = 5?
Less than 10
Greater than 0
Less than 10 and Greater than 0
10 or more
What will be the output of the following code?
Over 40
20 to 40
20 or less
None
What does the following code output if n = 10?
Divisible by 2 and 5
Divisible by 2
Divisible by 5
Not divisible by 2 or 5
What does the following code output if var = 'Python'?
Variable is not empty
Variable is empty
Error
None
Which of the following will correctly execute if x is less than y?
if x < y:
if x > y:
if x <= y:
if x >= y:
What is the correct syntax to check if a is not equal to b?
if a <> b:
if a != b:
if a =! b:
if a ^= b:
How can you test if 'x' is both greater than 10 and less than 20?
if x > 10 and < 20:
if 10 < x < 20:
if x > 10 and x < 20:
if (10 < x < 20):
What will be the output of the following code?
Even
Odd
Error
None
What does the following code output?
Greater
Equal
Smaller
None
What will be the output of the following code?
Greater than 20
Between 10 and 20
10 or less
None
What is the output of the following code?
Odd
Even
Error
None
Which of the following statements is correct for checking if a variable x is an even number?
if x // 2 == 0:
if x % 2 == 0:
if x / 2 == 0:
if x % 2 == 1:
Who created Python?
Guido van Rossum
Tim Berners-Lee
Larry Page
Mark Zuckerberg
What is Python known for?
High-level programming language
Low-level programming language
Assembly language
Hardware programming language
What is the purpose of the print() function in Python?
Display something in the console
Read user input
Perform mathematical calculations
Create a loop
What is the purpose of a code editor in an Integrated Development Environment (IDE)?
To write and edit code
To debug code
To compile code
To run code
What is the main advantage of using Python over Java?
More libraries
Better for system programming
Easier learning curve
Faster performance
What is the purpose of the PyCharm IDE?
General-purpose IDE
Specifically designed for Python development
Primarily for mobile app development
Focused on web development
What is the significance of indentation in Python programming?
Not required in Python
Used for decorative purposes
Optional for code execution
Very important for code readability
Which mode of using the Python interpreter allows for immediate code execution?
Script mode
Compile mode
Interactive mode
Debug mode
What type of language is Python?
Structured, declarative, mid-level
Functional, imperative, assembly
Compiled, procedural, low-level
Interpreted, object-oriented, high-level
Why Python is in demand?
Simple syntax
Useful in embedded and cross platforms
It is the fastest performing programming language
It has fewer libraries.
In programming, what is iteration/looping?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
numbers = [5, 14 ,9, 17]
for number in numbers:
if number >= 9:
print (number)
The output will be?
17
9
14
9
17
14
17
print(str(i) * 5)
print("i" * i)
print("i" * i)
print(str(i) * i)
for number in range(6):
print(number)
word= "computer"
for num in range(1,6):
print(word)
Which of the following programs prints ten lines?
for i in range(10):
print("hi")
for i = 1 to 10:
print("hi")
for i in 1 - 10:
print("hi")
for i from 0 to 9:
print("hi")
Which of the following best describes the purpose of a for loop?
A for loop is for doing something an indeterminate number of times.
A for loop is doing something an infinite number of times.
A for loop is for doing something a fixed number of times.
A for loop is for doing something three times.
Which of the following for loops would print the following numbers?
3
5
7
9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What is the value of num when this loop completes?
num = 0
for i in range(2, 8, 2):
num += i
2
8
12
20
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
What would be the output of the following code:
for i in range(3):
print(i)
1 2 3
i i i i
i i i
0 1 2
drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:
print(drink)
"coffee"
["coffee", "tea", "water", "juice", "soda"]
drink
"coffee tea water juice soda"
What would be the output of the following code:
for i in range(3):
print(5)
0 1 2
3 3 3 3 3
5 5 5
0 1 2 3 4
numbers = [2, 4, 6, 8]
for number in numbers:
print("hello!")
2 hello! 4 hello! 6 hello! 8 hello!
hello!
2 4 6 8
hello! hello! hello! hello!
You have a dictionary called student_scores that stores students' names as keys and their test scores as values. You want to find the student with the highest score. Which Python code snippet accomplishes this task?
max_score = max(student_scores.values())
max_score = max(student_scores)
max_score = student_scores.max_value()
max_score = max(student_scores.keys())
