Lecture 1 - Exercises

1A - Computers and Hardware

  1. Computers have (at least) two components that store information: main memory (RAM) and secondary storage (e.g., hard drives). Why are both needed?
  2. Which hardware component actually executes software instructions? Can it directly execute Python instructions?

1B - Algorithms and Pseudocode

  1. Write pseudocode for a program that repeatedly prompts a user for non-negative integers; once the user inputs a negative number, the program ends and outputs the sum of the input positive integers.

1C - Calling Functions, print, and input

  1. Which of the following lines of Python contain a comment?

    1. # Author: Professor Xavier
    2. print("Hello!") # greet the user
    3. input("Enter your favorite 2-digit number (##): ")
  2. What does the following code print?

    print("CSCI", 99 + 42, "at WWU")
  3. What does the following code print?

    print("CSCI", "99 + 42", "at WWU")
  4. How many arguments are given to the following call to the print function?

    print("CSCI", 99 + 42, "at WWU")