Amazon Introduction To Coding 3 — Questions and Answers
Question 1: What does an 'if' statement do?
- Executes code only when a condition is true (Correct answer)
- Repeats code forever
- Defines a new variable type
- Prints all variables
Correct answer: Executes code only when a condition is true
Conditional statements run a block of code only when a given condition evaluates to true.
Question 2: Which of these is an example of a string?
- "Amazon" (Correct answer)
- 100
- true
- 3.5
Correct answer: "Amazon"
A string is a sequence of characters, usually wrapped in quotation marks.
Question 3: What is the result of the operation 7 % 2 (modulo) in most languages?
- 1 (Correct answer)
- 3
- 0
- 14
Correct answer: 1
The modulo operator returns the remainder of division, and 7 divided by 2 leaves a remainder of 1.
Question 4: What is the purpose of a comment in code?
- To explain code to humans without affecting execution (Correct answer)
- To speed up the program
- To create a new variable
- To stop the program from running
Correct answer: To explain code to humans without affecting execution
Comments are notes ignored by the computer that help developers understand the code.
Question 5: Which keyword is commonly used to define a loop that runs a known number of times?
- for (Correct answer)
- if
- return
- class
Correct answer: for
A 'for' loop is typically used when the number of iterations is known in advance.
Question 6: What does 'syntax' refer to in programming?
- The set of rules for how code must be written (Correct answer)
- The speed of the program
- The color of the code editor
- The amount of memory used
Correct answer: The set of rules for how code must be written
Syntax defines the correct structure and grammar a programming language requires.
Question 7: What is an algorithm?
- A step-by-step set of instructions to solve a problem (Correct answer)
- A type of computer hardware
- A programming language
- A storage device
Correct answer: A step-by-step set of instructions to solve a problem
An algorithm is a defined sequence of steps used to accomplish a task or solve a problem.
What does an 'if' statement do?