In Python, what is the purpose of an if statement?
It is used for selection, executing a block of code only if a specified condition is true.
What is the role of the elif keyword in a Python selection statement?
It allows for checking multiple alternative conditions after an initial if statement fails.
In a Python if...elif...else structure, when is the else block executed?
It is executed when all preceding if and elif conditions evaluate to false.
What type of loop is created using the for i in range(0,10): syntax in Python?
A count-controlled loop.
In the Python code for i in range(0,10):, how many times will the loop iterate and what are the values of i?
The loop will iterate 10 times, with i taking values from 0 to 9.
What is the purpose of the while loop in Python?
It creates a condition-controlled loop that repeats as long as a specified condition remains true.
What function is used to get input from a user in Python?
The input() function.
How do you define a function in Python?
Using the def keyword, followed by the function name, parentheses for parameters, and a colon.
What does the return statement do inside a Python function?
It exits the function and sends a specified value back to where the function was called.
The process of converting a value from one data type to another is known as _____.
casting
Which Python function converts a value to an integer data type?
The int() function.
Which Python function would you use to convert the string "3.14" into a floating-point number?
The float() function.
Which Python function converts a numeric value into a string?
The str() function.
What is the Python operator for addition?
The + operator.
What is the Python operator for subtraction?
The - operator.
What is the Python operator for multiplication?
The * operator.
What is the Python operator for division that results in a float?
The / operator.
The % operator in Python performs which arithmetic operation?
Modulus (finds the remainder of a division).
What does the ** operator do in Python?
It performs exponentiation (raises a number to a power).
Which Python operator performs integer division (quotient), discarding the remainder?
The // operator.
What statement is used to open a file in Python, for example, to write to it?
The with open("filename.txt", 'w') as file: statement is commonly used.
What does the mode 'w' signify when opening a file in Python?
It opens the file in write mode, creating the file if it doesn’t exist or overwriting it if it does.
What is the purpose of opening a file with the mode 'a' in Python?
It opens the file in append mode, allowing content to be added to the end of the file without overwriting existing content.