IT 116: Introduction to Scripting
Answers to Mid-term Questions - Even Columns

Each of the following questions is worth 4 points.

  1. What do you call the variables that are listed inside the parentheses of a function header?
    parameters
  2. Will a while loop with the following header ever stop?
    while True:
    no
  3. What do you call a variable that is defined inside a function?
    a local variable
  4. What is the result of the following calculation in Python's interactive mode?
    2 + 3 * 5
    17
  5. Where do parameters get their values?
    from the corresponding argument in the function call
  6. If a variable is defined inside a function, can the code outside all functions see the value of that variable?
    no
  7. What is the result of the following calculation in Python's interactive mode?
    7 ** 2
    49
  8. What happens in a while loop when the boolean expression after the keyword while becomes false?
    the loop stops
  9. Where does the loop variable in a for loop get its values?
    from the list of values after in
  10. If you typed the following in Python's interactive mode, what would the result be?
    True or False
    True
  11. What do you call a loop that does not stop?
    an infinite loop
  12. Write the Python boolean literals.
    True and False
  13. What is the augmented assignment operator that multiples the value on its right by the value of the variable on its left and assigns that new value to the variable?
    *=
  14. If you want to stop a Python script running on Unix, what do you do?
    Control C
  15. If you typed the following in Python's interactive mode, what would the result be?
    True and False
    False
The following questions require you to write code.
Each question is worth 10 points.

  1. Define a function named is_divisible_by_seven which takes the single parameter named num.
    If num is evenly divided by 7 it should print "True", otherwise it should print "False".
    def is_divisible_by_seven(num):
        if num % 7 == 0:
            print("True")
        else:
            print('False')
  2. Write a for loop that prints the odd numbers from 3 to 11.
    You must use the range function with 3 arguments.
    for num in range(3, 12, 2):
        print(num)
  3. Write a while loop that prints the numbers 5, 10, 15, each on a separate line.
    You CANNOT use the range function here.
    You also CANNOT use a list.
    You will need to give a starting value to a variable which will be tested in the while loop.
    num = 5
    while num < 15:
        print(num)
        num += 5
  4. Write ONE if statement that prints "A" if the variable called score is 90 or more.
    Prints "B" when score is between 89 and 80.
    Prints "C" when score is between 79 and 70.
    Prints "D" when score is between 69 and 60.
    Otherwise it prints "F".
    if score >= 90:
        print("A")
    elif score >= 80:
        print("B")
    elif score >= 70:
        print("C")
    elif score >= 60:
        print("D")
    else:
        print("F")