IT 117: Intermediate Scripting
Quiz 4 Answers

  1. Write a for loop that prints the elements in set s1.
    for element in s1:
        print(element)
  2. Write a Python expression to see if the set s1 contains 5.
    5 in s1
  3. Write a Python expression that returns the union of the sets A and B.
    A.union(B) or B.union(A)
  4. Write a Python expression that returns the intersection of the sets A and B.
    A.intersection(B) or B.intersection(A)
  5. What is the name of the module that allows you to interact with the operating system?
    os
  6. Write the Python expression you would use to get a list of all entries in your current directory.
    os.listdir('.')
  7. Write the Python statement you would use to change your current directory to your parent directory.
    os.chdir('..')
  8. What is the name of the module that allows you to interact with the Python interpreter?
    sys
  9. Write the Python expression that gives the value of the first command line argument.
    sys.argv[1]
  10. Write the Python statement you would use to stop execution of a script.
    sys.exit()