Font size
S
M
L
XL
WorksheetsAS_Ch11_Programming
Total questions: 85
Worksheet time: 43mins
Name
Class
Date
1.
What is the primary purpose of a variable in programming?
a)
To create permanent memory storage
b)
To store and manipulate data that can change
c)
To define program structure
d)
To control program flow
2.
Which of the following is NOT a basic data type in Python?
a)
Integer
b)
String
c)
Boolean
d)
Function
3.
What does the input() function primarily do in Python?
a)
Print data to the screen
b)
Read user input from the keyboard
c)
Create a new variable
d)
Calculate mathematical operations
4.
In programming fundamentals, what does 'Sequencing' refer to?
a)
Sorting data in order
b)
Executing instructions in a specific order
c)
Creating loops
d)
Defining conditional statements
5.
What is the primary purpose of a selection statement (if-else)?
a)
To repeat a block of code
b)
To perform mathematical calculations
c)
To make decisions based on conditions
d)
To define new variables
6.
What does iteration in programming typically involve?
a)
Creating new variables
b)
Repeating a block of code multiple times
c)
Defining mathematical formulas
d)
Printing output to the screen
7.
What is the purpose of len() function when used with a string?
a)
To convert the string to uppercase
b)
To find the number of characters in the string
c)
To split the string into parts
d)
To remove spaces from the string
8.
What does the upper() method do to a string?
a)
Converts the string to lowercase
b)
Converts the string to uppercase
c)
Removes spaces from the string
d)
Counts the characters in the string
9.
Which operator is used for exponentiation in Python?
a)
^
b)
**
c)
*2
d)
pow()
10.
What is a nested selection statement?
a)
A selection statement with no conditions
b)
An if-else statement inside another if-else statement
c)
A loop that runs indefinitely
d)
A function that calls itself
11.
What is the key difference between a procedure and a function?
a)
Procedures cannot take parameters
b)
Functions always return a value
c)
Procedures are used only in mathematical calculations
d)
Functions cannot be called multiple times
12.
What is a parameter in a function?
a)
A variable that stores the function's result
b)
A value passed to a function when it is called
c)
The name of the function
d)
A constant used inside the function
13.
What is the primary purpose of reading from a file in Python?
a)
To create a new file
b)
To delete existing files
c)
To access and use data stored externally
d)
To encrypt file contents
14.
What is a one-dimensional array in Python?
a)
An array with no elements
b)
A list that can only store integers
c)
A single list of elements
d)
A complex mathematical structure
15.
What distinguishes a two-dimensional array from a one-dimensional array?
a)
It can store more types of data
b)
It has rows and columns (like a table)
c)
It is always larger in size
d)
It cannot be modified
16.
What does the open() function do when reading a text file?
a)
Creates a new file automatically
b)
Closes the file immediately
c)
Opens the file for reading or writing
d)
Deletes the file contents
17.
What is a logical operator in Python?
a)
A symbol used for mathematical calculations
b)
A keyword that connects logical conditions
c)
A function that returns True or False
d)
A method for sorting data
18.
What does 'writing to a file' typically involve?
a)
Reading file contents
b)
Deleting file contents
c)
Saving data to an external file
d)
Encrypting file data
19.
What is a boolean data type?
a)
A number with decimal points
b)
A data type that can only have True or False values
c)
A type of string
d)
A complex mathematical calculation
20.
What does 'maintainable program' generally refer to?
a)
A program that never crashes
b)
A program that is easy to understand and modify
c)
A program that runs very quickly
d)
A program with no bugs
21.
What is a constant in programming?
a)
A variable that can change value
b)
A value that cannot be modified after initial assignment
c)
A temporary storage location
d)
A function parameter
22.
Which of these is an integer data type?
a)
3.14
b)
True
c)
5
d)
'Hello'
23.
What does the print() function do?
a)
Read user input
b)
Display output on the screen
c)
Create a new variable
d)
Close a program
24.
In Python, what symbol is used for comments?
a)
//
b)
/* */
c)
#
d)
%%
25.
What does the modulo operator (%) do?
a)
Multiplication
b)
Division
c)
Returns the remainder of a division
d)
Exponentiation
26.
What is type casting?
a)
Creating a new data type
b)
Changing the type of a variable
c)
Deleting a variable
d)
Defining a constant
27.
What does the break statement do in a loop?
a)
Skips to the next iteration
b)
Exits the loop completely
c)
Repeats the loop
d)
Defines the loop condition
28.
What is the purpose of the continue statement?
a)
Stops the entire program
b)
Skips the rest of the current iteration
c)
Repeats the entire loop
d)
Creates a new loop
29.
Which loop is best when you know the number of iterations in advance?
a)
While loop
b)
Do-while loop
c)
For loop
d)
Recursive loop
30.
What does the split() method do to a string?
a)
Converts to uppercase
b)
Divides the string into a list
c)
Removes spaces
d)
Counts characters
31.
What is the default mode when opening a file for reading?
a)
w
b)
r
c)
a
d)
x
32.
Which method removes whitespace from both ends of a string?
a)
strip()
b)
trim()
c)
clean()
d)
remove()
33.
What does && represent in logical operators?
a)
Or
b)
Not
c)
And
d)
Exclusive or
34.
How do you create a multi-dimensional list in Python?
a)
Using multiple square brackets
b)
Using tuples
c)
Using dictionaries
d)
Using set()
35.
What is the purpose of the 'range()' function in a for loop?
a)
To generate a sequence of numbers
b)
To create random numbers
c)
To sort a list
d)
To count iterations
36.
How do you declare a global variable in a function?
a)
Using var keyword
b)
Using global keyword
c)
By passing it as a parameter
d)
It's automatically global
37.
What does the ord() function do in Python?
a)
Orders a list
b)
Returns the Unicode code point of a character
c)
Sorts strings
d)
Creates an ordered dictionary
38.
Which method is used to join elements of a list into a string?
a)
connect()
b)
merge()
c)
join()
d)
combine()
39.
What is tuple unpacking?
a)
Creating a new tuple
b)
Assigning multiple variables at once
c)
Removing items from a tuple
d)
Checking tuple contents
40.
How do you convert a string to a list of characters?
a)
str.split()
b)
list(string)
c)
string.tolist()
d)
char.convert()
41.
What does the 'pass' statement do?
a)
Exits a function
b)
Creates a placeholder with no action
c)
Stops a loop
d)
Returns a value
42.
Which method reverses a list in-place?
a)
list.reverse()
b)
reversed(list)
c)
list.back()
d)
reverse.list()
43.
What is list comprehension used for?
a)
Sorting lists
b)
Creating lists using a compact syntax
c)
Merging lists
d)
Counting list elements
44.
How do you check if a key exists in a dictionary?
a)
in keyword
b)
dict.exists()
c)
dict.contains()
d)
key.check()
45.
What does the 'enumerate()' function do?
a)
Sorts a list
b)
Counts list elements
c)
Adds index to iteration
d)
Removes duplicates
46.
Which method creates a deep copy of a list?
a)
list.copy()
b)
copy.deepcopy()
c)
list.duplicate()
d)
copy.clone()
47.
What is the purpose of *args in a function?
a)
To define mandatory arguments
b)
To pass a variable number of non-keyword arguments
c)
To create constant arguments
d)
To limit function arguments
48.
How do you round a number in Python?
a)
math.round()
b)
round()
c)
number.round()
d)
floor()
49.
What does the zip() function do?
a)
Compresses files
b)
Combines multiple iterables
c)
Sorts lists
d)
Creates a new list
50.
What is a lambda function?
a)
A complex mathematical function
b)
A small anonymous function
c)
A built-in Python library
d)
A way to create classes
51.
How do you handle exceptions in Python?
a)
Using if-else statements
b)
Using try-except blocks
c)
Using while loops
d)
Using switch statements
52.
What is the primary purpose of a recursive function?
a)
To create infinite loops
b)
To call itself within its own definition
c)
To generate random numbers
d)
To stop program execution
53.
What does the 'is' operator do in Python?
a)
Checks value equality
b)
Checks object identity
c)
Assigns a value
d)
Compares types
54.
How do you create a set in Python?
a)
Using []
b)
Using ()
c)
Using {}
d)
Using set()
55.
What is the purpose of __init__ method in a class?
a)
To delete the class
b)
To initialize class attributes
c)
To create a copy of the class
d)
To stop the class from running
56.
What does the map() function do?
a)
Creates a geographical map
b)
Applies a function to each item in an iterable
c)
Sorts a list of items
d)
Filters out specific items
57.
How do you convert a string to an integer?
a)
int.convert()
b)
int()
c)
string.toint()
d)
convert.int()
58.
What is the purpose of the 'finally' block in exception handling?
a)
To always execute code, regardless of whether an exception occurs
b)
To stop all exceptions
c)
To create a new exception
d)
To ignore all exceptions
59.
What does the 'del' keyword do?
a)
Creates a new variable
b)
Deletes a variable or object
c)
Defines a function
d)
Stops program execution
60.
How do you generate a random number in Python?
a)
Using random.random()
b)
Using math.rand()
c)
Using number.generate()
d)
Using system.random()
61.
What is the difference between append() and extend() for lists?
a)
There is no difference
b)
append() adds a single element, extend() adds multiple elements
c)
extend() is used for multiplication
d)
append() works only with numbers
62.
What does the pow() function do?
a)
Calculates square root
b)
Raises a number to a specified power
c)
Rounds a number
d)
Calculates absolute value
63.
How do you check the type of a variable?
a)
typecheck()
b)
type()
c)
var.type
d)
typeof()
64.
What is dictionary comprehension used for?
a)
Sorting dictionaries
b)
Creating dictionaries using a compact syntax
c)
Deleting dictionary items
d)
Counting dictionary elements
65.
What does the all() function do?
a)
Checks if all elements are the same
b)
Returns True if all elements in an iterable are true
c)
Counts all elements
d)
Adds all elements
66.
How do you remove the last item from a list?
a)
list.remove()
b)
list.pop()
c)
del list[-1]
d)
list.delete()
67.
What is the purpose of the 'with' statement?
a)
To create a loop
b)
To handle resource management
c)
To define a function
d)
To create a new variable
68.
What does the filter() function do?
a)
Sorts a list
b)
Creates a new list with elements that pass a test
c)
Removes duplicates
d)
Counts list elements
69.
What is a decorator in Python?
a)
A way to modify the appearance of a website
b)
A function that modifies another function
c)
A method for painting objects
d)
A way to create complex objects
70.
How do you convert a list to a tuple?
a)
list.totuple()
b)
tuple(list)
c)
convert.tuple()
d)
list.convert()
71.
What does the any() function do?
a)
Checks if any element is the same
b)
Returns True if any element in an iterable is true
c)
Counts all elements
d)
Adds all elements
72.
What is the purpose of the collections module?
a)
To create geographical collections
b)
To provide alternative data structures
c)
To sort complex data
d)
To delete data structures
73.
How do you create a shallow copy of a list?
a)
list.copy()
b)
copy.copy(list)
c)
list.duplicate()
d)
create.copy()
74.
What is the purpose of the 'nonlocal' keyword?
a)
To define global variables
b)
To reference variables in the outer (enclosing) scope
c)
To create new variables
d)
To stop variable modification
75.
What does the min() function do?
a)
Calculates maximum value
b)
Finds the smallest item in an iterable
c)
Rounds down a number
d)
Sorts a list
76.
How do you check if a list is empty?
a)
list.isEmpty()
b)
len(list) == 0
c)
list == []
d)
list.empty()
77.
What is the purpose of the repr() function?
a)
To repeat a function
b)
To create a string representation of an object
c)
To replace values
d)
To repeat a list
78.
How do you remove duplicates from a list?
a)
list.removeDuplicates()
b)
set(list)
c)
unique.list()
d)
list.distinct()
79.
What does the dir() function do?
a)
Creates a directory
b)
Lists all valid attributes of an object
c)
Sorts a list
d)
Deletes an object
80.
What is method chaining?
a)
Creating multiple methods
b)
Calling multiple methods in a single line
c)
Linking class methods
d)
Creating method hierarchies
81.
How do you convert a list to a string?
a)
str(list)
b)
list.toString()
c)
''.join(list)
d)
convert.string(list)
82.
What is the purpose of the iter() function?
a)
To create an iterator object
b)
To repeat a function
c)
To sort an iterable
d)
To count iterations
83.
How do you get the absolute value of a number?
a)
math.abs()
b)
abs()
c)
number.absolute()
d)
absolute.value()
84.
What does the sum() function do?
a)
Multiplies all numbers in an iterable
b)
Adds all numbers in an iterable
c)
Finds the average of numbers
d)
Sorts numbers
85.
What is the purpose of the 'yield' keyword?
a)
To stop a function
b)
To create a generator function
c)
To return a value
d)
To create a new variable
Reset
