Assessment 2. Quiz 2


Quiz #2

Quiz 2 will be held in-class in NVIDIA auditorium on Wednesday, July 27th, from 9:45am - 10:45am. You should plan on being present in lecture for the quiz. If you are an SCPD / remote student, you should receive another email with quiz details.

  • The quiz will cover all of the material up to and including drawing. This includes lists, if/elif/else statements, grids, and drawing. We will include a drawing reference for you for the quiz.
    • The quiz will have three programming problems
    • Although we will not take off points for syntax errors, we do expect that your code will be proper Python code. If we cannot determine what you meant by your answer, you will not receive full credit.
    • The quiz is open book, open notes. There are some rules:
      • You are not allowed to look up the specific question online. E.g., if the question was, "write a function to calculate the sum of all the numbers from 1 to 1000," you could not look up "code to calculate the numbers from 1 to 1000" online.
      • You may not ask anyone else for help (text/email/etc).
    • By taking the quiz, you are implicitly agreeing to follow the Stanford Honor Code, and if we detect any violations of the Stanford Honor Code during the quiz, you will receive a 0 on the quiz, and we will forward a report to the Stanford Office of Community Standards for further penalties.
  • Bring the following to class:
    1. A laptop with web access. If you do not have access to a laptop, please reach out to Chris and Tori to make other arrangements.
      • We will have a limited supply of power outlets if your computer will not last through the entire quiz.
    2. A mask. We will not let anyone take the in-person quiz without a mask.
    3. Scrap paper and a pen/pencil. The paper must be blank when you start the quiz.
  • The quiz will be delievered on a web page. You can find an example quiz here: Practice Quiz 2.
  • After you finish each problem, you should press one of the "submit" buttons. This will submit all the code for all your problems. We will grade your last submission.

We will give you the following reference information for Grid and Drawing on the quiz:

Grid Reference

  • grid.width, grid.height: width/height properties.
  • grid.get(x, y): returns contents at x, y.
  • grid.set(x, y, val): sets the contents at x, y to be val (error if x, y out of bounds).
  • grid.in_bounds(x, y): returns True if the (x, y) location is in the grid.

Drawing Reference

  • To create a Canvas:
    canvas = DrawCanvas(500, 300, title='Drawing Window')
    
  • Functions:
    # draw a line from x1, y1 to x2, y2
    draw_line(x1, y1, x2, y2)
    
    # draw an empty rectangle
    draw_rect(x, y, width, height)
    
    # draw a filled rectangle
    def fill_rect(x, y, width, height):
     
    # draw an empty oval 
    def draw_oval(x, y, width, height):
      
    # draw a filled oval
    def fill_oval(x, y, width, height):
    
    # draw a string of text at x, y
    def draw_string(x, y, text):
    
    # By default, drawing is in black. 
    # An optional `color='red'` parameter can
    # be added to any of the draw functions to 
    # draw in that color, e.g.,
    fill_oval(x, y, width, height, color='green')
    
    # Instead of a color string, code may instead pass 
    # a red, green, blue value as a parenthesized "tuple", 
    # which is similar to a list, but immutable.0
    # For example, the rgb tuple `(255, 255, 0)` would be yellow.
    # For a completely red oval, you could pass in a color like this:
    fill_oval(x, y, width, height, color=(255, 0, 0))