IT 116: Introduction to Scripting
Answers to Midterm Questions - Even Columns

Each of the following questions is worth 4 points.

  1. What do you call the expressions (values), inside a function call?
    arguments
  2. If you typed the following in Python's interactive mode, what would the result be?
    True or False
    True
  3. Where do parameters get their values?
    from the corresponding argument in the function call
  4. What do you call a statement that runs a function?
    a function call
  5. If you typed the following in the Python interactive mode, what would the result be?
    True and False
    False
  6. What do you call a series of statements that has a name and performs some task?
    a function
  7. What do you call a value written out directly inside the code?
    a literal
  8. What are the four types of expressions?
    literals, variables, calculations, function calls
  9. If range is run with two arguments, what does the first of the two arguments specify?
    the first number in the list
  10. What do you call one or more lines of code that perform a complete action?
    a statement
  11. What arithmetic operators have the highest precedence (parentheses are NOT operators)?
    **
  12. What do you call the variables that are listed inside the parentheses of a function header?
    parameters
  13. If range is run with three arguments, what does the third of the three arguments specify?
    the difference between each number in the list
  14. If range is run with only one argument, what does that argument specify?
    one more than the last number in the list
  15. What is an expression?
    anything that can be turned into a value
The following questions require you to write code.
Each question is worth 10 points.

  1. Define the function named is_divisible_by_three which takes the single parameter num.
    If num is evenly divided by 3, it should print "True".
    Otherwise it should print "False".
    You will need to use the remainder operator %.
    def is_divisible_by_three(num):
        if (num % 3 == 0):
        print("True")
    else:
        print('False')
  2. Write a for loop that prints the EVEN numbers from 2 to 10 using the range function.
    for num in range(2,11,2):
        print(num)
  3. Write a while loop that prints the numbers from 1 to 10, 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.
    Inside the loop you will need to increase the variable by 1.
    num = 1
    while num <= 10:
        print(num)
        num += 1
  4. Write an if-elif-else statement that behaves like a traffic light.
    This statement should test the value of the variable named signal.
    If signal is "green" it should print "Go".
    If signal is "yellow" it should print "Slow".
    If signal is "red" it should print "Stop".
    Otherwise it should print "Error".
    You should assume that signal already has a value.
    if signal == "green":
        print("Go")
    elif signal == "yellow":
        print("Slow")
    elif signal == "red":
        print("Stop")
    else:
        print("Error")