IT 116: Introduction to Scripting
Quiz 4 Answers

  1. What is the name of the Python function used to create a list of numbers in a for loop?
    range
  2. If the function mentioned above were run with the single argument 5, what is the list of numbers that would be created?
    0, 1, 2, 3, 4
  3. If the function mentioned above were run with the two arguments 1 and 5, what is the list of numbers that would be created?
    1, 2, 3, 4
  4. If the function mentioned above were run with the three arguments 1, 10 and 2, what is the list of numbers that would be created?
    1, 3, 5, 7, 9
  5. If the function above is run with only one argument, what does that argument specify?
    one more than the last number in the list
  6. If the function above is run with two arguments, what does the first of the two arguments specify?
    the first number in the list
  7. Write a for loop that prints the values from 1 to 10, each on a separate line.
    for number in range(10):
        print(number + 1)
  8. What is the augmented assignment operator that adds the value on it's right to the value of the variable on it's left and assigns that new value to the variable?
    +=
  9. What is the augmented assignment operator that subtracts the value on it's right from the value of the variable on it's left and assigns that new value to the variable?
    -=
  10. Write a loop that checks the value of the variable named number to see that it is greater than 0, and, if it is not, prints an error message and asks for another integer.
    while number <= 0:
        print("The value must be greater than 0")
        number = int(input("Please enter a number greater than 0"))