WorksheetsS3 Code Comments & Variables
Total questions: 1
Worksheet time: 33mins
Why is it important to add comments to code?
To make the code run faster
To add more lines of code
To improve the readability of code
To change the functionality of the code
What can happen as programs grow and expand?
They can become easier to read
They require fewer comments
They can become complicated to read
They become shorter
What is the purpose of comments in code?
To cause errors in the program
To be executed as part of the program
To explain what the program is doing and how it is doing it
To change the flow of the program
Who benefits from comments in the code?
The computer
The programmer and others reading the code
External devices interacting with the code
The program's execution speed
What is NOT a function of comments in code?
Ignored by the computer
Highlights important sections of code
Can remind the programmer of how their code works
Increases the execution speed of the program
Where is it considered good practice to insert multi-line comments in a program?
At the bottom of the program
In the middle of the program
At the top of the program
Outside the program file
What information should multi-line comments contain?
Only the name of the program
Only the author's name and date
The name of the program, author, date, and description of what the program will do
Random notes and reminders
How are multi-line comments in a program typically started and ended?
With a single quotation mark
With a hash symbol (#)
With a double slash (//)
With three quotation marks
What symbol is used to add single line comments in code?
//
/*
#
What is the purpose of using single line comments in code?
To change the functionality of the code
To compile the code faster
To explain certain aspects of the code
To create a new variable
Single line comments are also used to:
Execute a specific line of code
Highlight different sections
Import external libraries
Define functions
What is a variable in the context of programming?
A. A constant value that does not change throughout the program
B. A storage location reserved in memory that stores a value used within a program
C. A function that performs a specific task within a program
D. A type of programming language
Can a variable's value change during the execution of a program?
No, it remains constant
Yes, but only at the beginning
Yes, it can change throughout the process of the program
No, it can only change when the program ends
What should all variables be given to describe their contents?
A. A unique number and color code
B. A data type and suitable identifier
C. A complex algorithm
D. A fixed position in the memory
Are variables able to store multiple types of data at once?
A. Yes, they can store as many types as needed
B. No, they are only able to store one particular type of data
C. Yes, but only two types of data simultaneously
D. No, they cannot store any data
What data type would you use to represent whole numbers?
Float
String
Integer
Boolean
Which data type is used to represent individual letters and symbols?
Boolean
Char
Integer
Float
If you need to store a decimal number, which data type should you choose?
Char
Boolean
String
Float
What is a String data type used to represent?
True or False values
Collection of characters
Whole numbers
Decimal numbers
What must a variable name begin with in Python?
A) A number
B) A special character other than underscore
C) A letter (a-z, A-Z) or an underscore
D) Any character is acceptable
Which of the following is true about the characters that can be used in a Python variable name after the first character?
A) Only letters and numbers
B) Only letters, numbers, and special characters
C) Only letters, numbers, or underscore
D) Any characters without restriction
Are variable names in Python case sensitive?
A) No, they are not case sensitive
B) Yes, they are case sensitive
C) Only the first character is case sensitive
D) Case sensitivity depends on the version of Python
Can reserved words in Python be used as variable names?
A) Yes, but it is not recommended
B) Yes, without any restrictions
C) No, because Python uses them for other things
D) Only if they are written in uppercase
When naming variables, why is 'student_no' considered better than 'sn'?
Because 'sn' is more meaningful
Because 'student_no' is shorter and easier to type
Because 'student_no' is more meaningful
Because 'sn' maintains the length of a variable name
Which of the following variable names is too long according to best practices?
student_no
age_in_years
length_in_meters
roll_no_of_a_student
What is important to include in variable names to avoid confusion?
The type of programming language used
The color of the variable name
Units of measurement
The name of the programmer
According to best practices, how should you be when naming variables?
Inconsistent
Consistent
Complicated
Vague
According to best practices, where should you declare all the variables you are planning to use in your program?
At the bottom of your program
Just under the multi-line comments at the top of your program
In the middle of your program
After every function
What must you type first when declaring a variable?
The value you want to assign to the variable
The identifier you have chosen along with the variable type
A comment explaining the variable
The variable type only
What is a good practice when determining how many variables a program needs?
Guess the number of variables needed
Look at the program specification and underline the information that needs to be stored
Always use a fixed number of variables for every program
Avoid using variables to make the program simpler
How many variables are needed for a program that calculates the area of a rectangle and displays it to the user?
1
2
3
4
What should each variable in a program be given?
A random identifier and any data type
The same identifier and data type
A useful identifier and an appropriate variable type
No identifier until the program is completed
What are the three main components involved in all programs according to the learning material?
Input, Storage, Output
Input, Processing, Output
Input, Processing, Storage
Storage, Processing, Output
When writing basic programs in Python, what is necessary to know?
How to take in information from the user, how to store that information, and how to display information to the user
How to take in information from the user, how to manipulate that information, and how to display information to the user
How to manipulate information from the user, how to store that information, and how to process information to the user
How to process information from the user, how to manipulate that information, and how to store information for the user
Which Python function is used to get input from the user?
print()
type()
input()
int()
How is the input for the 'age' variable processed in the code?
It is taken as a string and then converted to an integer.
It is directly taken as an integer.
It is taken as a float and then converted to an integer.
It is not processed and remains a string.
What is the output of the code snippet: print("Hello World!")?
Hello World!
Hello + World!
"Hello World!"
print Hello World!
What does the '+' character do in the context of the code snippet: print("Hello " + name + " it is nice to meet you.")?
Adds a numerical value to the name
Subtracts the string "name" from "Hello "
Concatenates the strings "Hello ", name, and " it is nice to meet you."
Causes a syntax error
According to the comment in the code, what must be done before concatenating a number to a string?
The number must be divided by a string
The number must be converted to a string
The number must be multiplied by a string
The number can be concatenated without any conversion
What is another term for changing the data type of a variable in programming?
Type conversion
Variable morphing
Data typing
Type casting
Why might it be necessary to change the data type of a variable in a program?
To increase the speed of the program
To reduce the memory usage
To match the data type expected by a function or operation
To make the code look cleaner
When a user enters a number from the keyboard, what is the default data type of that input in many programming environments?
Integer
Float
String
Character
What data types might you want to convert keyboard input into for processing in a program?
String and Character
Integer and Double
Integer and Float
Boolean and Array
What Python function is used to convert a string input to an integer?
str()
int()
float()
input()
Which line of code will output a float number after conversion?
number = int(input("Please enter a number using the keyboard: "))
number = float(input("Please enter a number using the keyboard: "))
newNumber = float(number)
newString = str(number)
If the variable 'number' is set to 16, what will be the type of 'newString' after the following operation: newString = str(number)?
Integer
Float
String
List
How often do most programs need to carry out calculations?
At least once
Only for complex operations
Rarely ever
Never
Which symbol is used for addition in the syntax provided?
*
+
/
=
What symbol represents subtraction in the given syntax?
+
*
-
=
Which symbol stands for division in the syntax shown?
+
-
*
/
What is the symbol for multiplication in the syntax used?
+
-
*
/
What symbol is used to denote equals or assignment in the syntax?
+
-
*
=
What does the letter 'B' in BODMAS stand for?
Base
Brackets
Binary
Balance
According to BODMAS, which of the following should be performed first in a calculation?
Addition
Division
Brackets
Subtraction
What does 'DM' in BODMAS represent?
Decimal and Modulus
Division and Multiplication
Diameter and Mean
Distance and Mass
What is the correct order of operations in BODMAS?
Addition, Subtraction, Division, Multiplication, Orders, Brackets
Brackets, Orders, Division, Multiplication, Addition, Subtraction
Division, Multiplication, Addition, Subtraction, Brackets, Orders
Orders, Brackets, Addition, Subtraction, Multiplication, Division
What does the letter 'O' in BODMAS stand for?
Output
Origin
Orders
Opportunity
What is the result of the expression 4 x 3 + 2?
A) 14
B) 20
C) 10
D) 12
What is the result of the expression 4 x (3 + 2)?
A) 14
B) 20
C) 10
D) 12
What should be identified before attempting to code a program on the computer as it becomes more complicated?
Inputs, processes, and outputs
Errors and bugs
Programming language and IDE
User interface design
What is often involved in the process applied to variables in programming?
A calculation or a decision
A loop or an array
A function or a class
A variable declaration or assignment
What is the purpose of identifying variables for output in programming?
To optimize the program's performance
To display the final information to the user
To debug the program
To choose the appropriate data type
