NEW
Font size
S
M
L
XL
WorksheetsPython Programming: Functions, Data Structures, and Loops Assessment
Total questions: 20
Worksheet time: 10mins
Name
Class
Date
1.
What is the primary advantage of using functions in programming according to the fundamental principles of software development?
a)
Functions allow code reusability and reduce repetition
b)
Functions automatically fix bugs in code
c)
Functions make programs run faster
d)
Functions make variables global by default
2.
When analyzing the syntax 'def fun():', what would happen if you wrote 'def fun' without the parentheses and colon?
a)
The function would work normally
b)
Python would throw a syntax error
c)
Python would create a variable instead of a function
d)
The function would only work once
3.
If you have a function that calculates area and you want to reuse it in multiple projects, which programming principle does this demonstrate?
a)
Code compilation
b)
Code encryption
c)
Code modularity and reusability
d)
Code optimization
4.
Why would a programmer choose to break down a complex program into multiple functions rather than writing everything in one large block of code?
a)
To make the program run in parallel
b)
To reduce memory usage
c)
To make the program file smaller
d)
To improve code organization, readability, and maintainability
5.
When a function is designed to 'take input (parameters) and return output', what programming concept is being implemented?
a)
Variable declaration
b)
Input-output processing
c)
Memory allocation
d)
Data encapsulation
6.
In the context of the activity 'Checking Even Numbers', what logical structure would most likely be implemented within the function?
a)
An if-else conditional statement
b)
A try-except block
c)
A while loop only
d)
A for loop only
7.
For the activity 'Counting vowels in a sentence' that uses 'for loop within the function', what is the most efficient approach?
a)
Use nested loops to compare each character with each vowel
b)
Sort the sentence alphabetically first
c)
Convert the sentence to uppercase first, then check each character
d)
Check each character once and count matches
8.
When implementing the 'Finding Largest Number' activity, which algorithmic approach would be most effective?
a)
Use a random selection method
b)
Sort all numbers first, then return the last element
c)
Compare each number with a running maximum value
d)
Add all numbers and divide by count
9.
In the 'Reversing a String' activity that uses 'Recursive function', what is the base case most likely to be?
a)
When the string is empty or has one character
b)
When the string length equals 10
c)
When the string contains only vowels
d)
When the string contains spaces
10.
For the 'Calculating Distance' activity that uses 'input() function', what data type conversion is most likely needed?
a)
No conversion is needed
b)
Convert input to boolean for logical operations
c)
Convert input to integer or float for mathematical operations
d)
Convert input to list for iteration
11.
When designing a function for 'Multiplying Numbers', what parameter design would provide the most flexibility?
a)
Accept only string parameters
b)
Accept a variable number of parameters (*args)
c)
Accept exactly two parameters only
d)
Accept no parameters and use global variables
12.
In the 'Finding Sum of Array' activity, why would you use len() function within your custom function?
a)
To find the maximum value
b)
To convert the array to a string
c)
To sort the array elements
d)
To determine how many elements to iterate through
13.
For the 'Removing VOWELS' activity that uses 'char()' and 'Operator(+=)', what is the most logical sequence of operations?
a)
Sort characters alphabetically, then remove vowels
b)
Check each character, if not a vowel, add to result string
c)
Remove all characters first, then add back consonants
d)
Convert to numbers, perform arithmetic, convert back
14.
When implementing 'Calculating Hypotenuse' using 'Operators ( +, **)', which mathematical principle is being applied?
a)
Trigonometric ratios
b)
Quadratic formula
c)
Pythagorean theorem (a² + b² = c²)
d)
Linear algebra
15.
In the 'Counting Words in a sentence' activity using len(), what preprocessing step would be most important?
a)
Remove all punctuation marks
b)
Count only alphabetic characters
c)
Convert all letters to lowercase
d)
Split the sentence into individual words
16.
For 'Calculating Surface Area and Volume' activity, what type of function design would be most appropriate?
a)
A function that stores results in global variables
b)
Two separate functions, one for each calculation
c)
A function that only prints results without returning values
d)
One function that calculates both values and returns a tuple
17.
When analyzing the function call syntax 'fun()', what distinguishes this from a variable reference?
a)
The presence of parentheses
b)
The capitalization of the name
c)
The position in the code
d)
The length of the name
18.
In the context of 'String slicing' mentioned in activity 14, what advantage does this provide in function implementation?
a)
It converts strings to integers
b)
It makes strings immutable
c)
It allows access to specific portions of strings without loops
d)
It automatically sorts string characters
19.
For the 'Calculating Percent Markup' activity, what validation should the function include?
a)
Confirm inputs are less than 100
b)
Verify inputs are whole numbers only
c)
Check that inputs are positive numbers
d)
Ensure inputs are strings
20.
When implementing 'Greeting People' functionality, what makes a function more versatile than hardcoded text?
a)
Functions can accept different names as parameters
b)
Functions automatically format text
c)
Functions use less memory
d)
Functions run faster than print statements
Reset
