Foundations of Programming Quiz 2

Choose the best answer for each question. Click Check Answers at the bottom to see how you did!

    1. Which of the following is a valid variable name?
    In most programming languages, variable names can't start with a number or include spaces or hyphens. variable_1 is valid.
    2. What does the expression 3 + 4 * 2 evaluate to?
    According to order of operations, multiplication happens first: 4 * 2 = 8, then 3 + 8 = 11.
    3. Which of these is the best description of a function?
    Functions are reusable blocks of code that perform specific tasks and can be called multiple times.
    4. What is the value of not (True and False)?
    True and False is False, and not False is True.
    5. What does the elif keyword do in an if statement?
    elif stands for "else if" and allows you to test more conditions if the first if is false.
    6. What is the result of 7 % 3?
    The modulus operator % gives the remainder. 7 divided by 3 is 2 with a remainder of 1.
    7. What happens if you try to use a variable before assigning it a value?
    In most languages, referencing a variable before assigning it a value causes a runtime or compile error.
    8. What does this code print?
    if 5 > 3:
      print("A")
    else:
      print("B")
    The condition 5 > 3 is true, so the code prints "A".
    9. What is the purpose of indentation in Python?
    In Python, indentation is part of the syntax. It defines which lines of code belong together, like inside a loop or function.
    10. Which of these will result in a syntax error?
    The string in option A is missing an ending quotation mark, which causes a syntax error in most languages.