CPSC120B
Fundamentals of Computer Science I

Review 1

A practice test to review for the first test.

  1. What is the significance of initializing the accumulator variable? How do we determine what this starting value should be?

  2. For each of the following snippets of Python code, give what would be executed if run. If the snippet will not run because of an error, explain the error.

    1. print(7 // 2)
    2. print(7 / 2)
    3. print(7 % 2)
    4. for i in range(-10, 10, 3):
          print(i, end=" ")
            
    5. for i in range(0, 5):
          for j in range(i, 5):
              print(j, end=", ")
          print()
            
    6. import turtle
      
      window = turtle.Screen()
      myrtle = turtle.Turtle()
      
      myrtle.forward(100)
      myrtle.right(90)
      myrtle.forward(100)
      myrtle.right(135)
      myrtle.forward(142)
      
      window.exitonclick()
            
  3. Write a python program that prompts the user to enter three integers via the command line. Your program should then print the average of the 3 integers the user typed in.

  4. Write a python program that prints all multiples of 9 that are less than 1000.