Worksheetspy_2
Total questions: 42
Worksheet time: 21mins
How can comments be used in Python programming?
To execute code
To document code
To increase execution speed
To create variables
Which of the following best explains the use of str, int, and float values and variables in Python?
They are used to store and manipulate text, whole numbers, and decimal numbers respectively.
They are used to define functions and classes in Python.
They are used to handle file operations in Python.
They are used to manage memory allocation in Python.
What are arithmetic expressions in Python?
A combination of numbers and operators that computes a value
A type of loop in Python
A function definition in Python
A syntax error in Python
How is string concatenation performed in Python?
Using the '+' operator
Using the '-' operator
Using the '*' operator
Using the '/' operator
What are special characters in strings, and how are they used in Python?
Special characters are used to format strings.
Special characters are used to represent whitespace.
Special characters are used to escape characters in strings.
Special characters are used to concatenate strings.
Which of the following describes the use of the built-in functions print(), input(), str(), float(), int(), and round() in Python?
They are used for file handling operations.
They are used for mathematical computations only.
They are used for basic input/output and type conversion operations.
They are used for network programming.
Function chaining in Python is used to:
Execute multiple functions in a single line
Create a chain of linked lists
Connect multiple Python scripts
Chain decorators together
What is the purpose of indentation in Python coding?
To improve code readability
To define code blocks
To make the code run faster
To add comments to the code
Which of the following describes the use of Python comments, including 'commenting out' portions of Python code?
Python comments are used to explain code and can be used to temporarily disable code by 'commenting out'.
Python comments are used to execute code faster.
Python comments are used to compile code.
Python comments are used to encrypt code.
Which of the following describes the data types: str, int, float?
str is a string, int is an integer, float is a floating-point number.
str is a number, int is a string, float is a character.
str is a floating-point number, int is a string, float is an integer.
str is a character, int is a floating-point number, float is a string.
Which of the following are recommendations for creating a Python variable name?
Use meaningful names
Start with a number
Include special characters
Use underscores to separate words
Distinguish between underscore notation and camel case.
Underscore notation uses underscores to separate words, while camel case capitalizes the first letter of each word except the first.
Camel case uses underscores to separate words, while underscore notation capitalizes the first letter of each word except the first.
Both underscore notation and camel case use underscores to separate words.
Both underscore notation and camel case capitalize the first letter of each word except the first.
Which of the following describes the evaluation of an arithmetic expression, including order of precedence and the use of parentheses?
Evaluation is done from left to right, ignoring parentheses.
Operators with higher precedence are evaluated first, and parentheses can alter the precedence.
All operations are evaluated simultaneously.
Parentheses are ignored in arithmetic expressions.
Distinguish among these arithmetic operators: /, //, and %.
The / operator performs integer division, // performs floating-point division, and % gives the remainder.
The / operator performs floating-point division, // performs integer division, and % gives the remainder.
The / operator gives the remainder, // performs integer division, and % performs floating-point division.
The / operator performs integer division, // gives the remainder, and % performs floating-point division.
What is the use of the += operator in a compound arithmetic expression?
It adds the right operand to the left operand and assigns the result to the left operand.
It subtracts the right operand from the left operand and assigns the result to the left operand.
It multiplies the right operand with the left operand and assigns the result to the left operand.
It divides the left operand by the right operand and assigns the result to the left operand.
Which of the following functions is used to convert a string to an integer in Python?
int()
float()
print()
str()
input()
What is the consequence of incorrect indentation in Python?
It causes an error
It improves performance
It has no effect
It makes the code run faster
What is the purpose of the 'counter' variable in the given Python program?
To keep track of the number of iterations
To store the final result of the program
To act as a flag for conditional statements
To hold temporary data during execution
In the given Python program, what is the condition for the while loop to continue executing?
The loop continues while a variable is less than 10.
The loop continues while a variable is not equal to 0.
The loop continues while a variable is greater than 5.
The loop continues while a variable is equal to 1.
What is one reason to use comments in code?
To make the code run faster
To explain the purpose of the code
To increase the file size
To confuse other developers
True or False: You should use comments to describe portions of code that are hard to understand, but don’t overdo them.
True
False
What is an example of a string data type in Python?
A) 21
B) 'Mike'
C) 21.9
D) -25.2
Fill in the blank: An example of an integer data type in Python is ____.
450
45.0
'450'
True
Which of the following is a floating-point data type example in Python?
'Please enter name: '
0
3.1416
-25
Which of the following is a correct rule for naming a variable in Python?
A) A variable name must begin with a number.
B) A variable name can contain spaces.
C) A variable name must begin with a letter or underscore.
D) A variable name can be the same as a keyword.
True or False: A variable name can begin with a number, but can use numbers later in the name.
True
False
What is the use of the 'break' keyword in Python?
To exit a loop prematurely
To pause the execution of a program
To define a function
To handle exceptions
What is the use of the 'continue' keyword in Python?
To exit a loop immediately
To skip the current iteration and continue with the next
To pause the execution of a loop
To terminate the program
What is the use of the 'elif' keyword in Python?
To define a function
To handle exceptions
To specify an alternative condition
To import a module
What is the use of the 'else' keyword in Python?
To execute a block of code if a condition is true
To execute a block of code if a condition is false
To execute a block of code after a loop completes
To define a function
What is the use of the 'for' keyword in Python?
To define a function
To create a loop
To handle exceptions
To declare a variable
What is the use of the 'if' keyword in Python?
To define a function
To create a loop
To make a decision based on a condition
To import a module
What is the use of the 'while' keyword in Python?
To define a function
To create a loop that continues until a condition is false
To import a module
To handle exceptions
Fill in the blank: Start all variable names with a ________ letter.
lowercase
uppercase
capital
numeric
Which of the following is a recommendation for naming variables?
A) Use uppercase letters for all variable names
B) Use the names of built-in functions
C) Use meaningful names that are easy to remember
D) Use numbers at the beginning of variable names
What is the name of the Python operator '+'?
Subtraction
Addition
Multiplication
Division
What is the name of the Python operator '-'?
Subtraction
Addition
Multiplication
Division
What is the name of the Python operator '*'?
Subtraction
Addition
Multiplication
Division
What is the name of the Python operator '/'?
Subtraction
Addition
Multiplication
Division
What is the name of the Python operator '//'?
Integer division
Modulo
Exponentiation
Addition
What is the name of the Python operator '%'?
Integer division
Modulo
Exponentiation
Addition
What is the result of 25 / 4? Fill in the blank: 25 / 4 = ___.
6.25
5.5
7
6
