LMU ☀️ CMSI 1010
COMPUTER PROGRAMMING LABORATORY
Exam 1

Options with circles are single-select (exactly one), while options with squares are multi-select (zero or more).

  1. In under 10 words, what is the difference between a parameter and an argument?
  2. What is the result of the Python expression "na" * 16 + " batman"?
  3. What are actual benefits of labeling arguments in calls?
    • It makes the code run a lot faster
    • It makes it easier to see how many arguments are being passed
    • It allows arguments to be specified in any order
    • It helps prevent mistakes when calling functions with many parameters
    • It improves code readability
  4. You've just started a new project in a fresh folder and would like to manage your folder with Git. What command should you do first?
    • git log
    • git remote
    • git config
    • git init
    • git status
  5. Which of the following are possible results of the command mv fish sea?
    • Renaming the file fish to have the new name sea
    • Moving the file fish into the folder named sea
    • An error
    • Moving the files fish and sea into your home folder
    • Moving the file sea into the folder named fish
  6. What command is used to download files from the Internet?
  7. What commands are used to (a) create a file and (b) create a folder?
  8. When doing git commit from the command line, what exactly comes after the word commit? Show a specific example with full command syntax.
  9. What has to be in place before you can invoke git push?
  10. There are some files that should never be managed by Git. What is the best way to ensure they don't get into your repository?
    • Keep them in a separate folder from the project files you do want managed by Git
    • Be really careful to never git add them
    • Start the filename with a dot, which makes the file a hidden file
    • Add their names to the .gitignore file
  11. Which of the following are actual advantages that can be gained by introducing functions?
    • To make code more readable
    • To reduce the need for comments
    • To make code more flexible
    • To make printing faster
  12. Which command creates a virtual environment?
    • python -m venv
    • source
    • venv
    • activate
  13. Which command adds other people's libraries to your code?
    • source env/bin/activate
    • tree
    • pip install
    • python -m venv env
    • import
  14. What values are in range(3, 0, -2)?
    • 3, 2, 1, 0, -1, -2
    • 3, 2, 1, 0, -1
    • -2, -1, 0, 1, 2
    • 3, 1
  15. Suppose x and y were variables. Give a Python expression for the string that expresses, in English, that x and y have the sum that they do. For example, if x is 5 and y is 8, the string should be exactly
    The sum of 5 and 8 is 13
    
  16. Write a function to determine if a number is positive.
  17. Which of the following give you all but the first and last element of the list called friends?
    • friends[1 : len(friends)-1]
    • friends[0 : -1]
    • range(friends, 0, -1)
    • friends[0 : len(friends)-1]
    • friends[1 : -1]
  18. How do you enter the Python REPL (or shell), assuming your machine's Python system had the python command rather than python3?
    • With the command python repl
    • With the command python
    • With the command python --shell
    • With the command python --version
    • With the command python shell
  19. In a Python match statement, what keyword is used to specify a pattern to match against?
  20. Given a dictionary called capitals with contents such as {"CA": "Sacramento", "HI": "Honolulu", ...}, how would you select a random state?
    • random.choice(list(capitals.keys()))
    • random.choice(capitals)
    • capitals[2]
    • random_state()