⚠
Privacy Notice: When you sign in with GitHub, your quiz attempts are stored in Google Firebase so you can track your progress. This data is only accessible to the course instructor, is not otherwise shared, and will be deleted at the end of the semester. For earlier deletion, contact the instructor. Prefer to stay anonymous? Use guest mode or a GitHub account without your real name.
Loading...

02 Exercise: PEP 8 Before/After Analysis

Score: 0 / 14

Instructions

This quiz tests your ability to analyze PEP 8 improvements in real Python code. You will compare “Before” (non-compliant) and “After” (compliant) versions of code snippets and identify the specific differences, rules applied, and reasoning behind each change.

Topics covered:

  • Spacing around operators and after commas
  • Import organization (grouping, sorting, unused imports)
  • Naming conventions (PascalCase, snake_case, UPPER_CASE)
  • Compound statements vs. separate lines
  • Multi-line formatting for function calls
  • Git diff implications of code formatting

Tip: Read both code versions carefully before answering. Small differences like a single space or a line break count as distinct improvements.

Question1 Difference Analysis

How many PEP 8 improvements were made between the Before and After versions?

Before:

def calc(a,b):return a+b

After:

def calc(a, b):
    return a + b

Enter a number:

Question2 Rule Identification

Which PEP 8 rules were applied in the After version?

Before:

def calc(a,b):return a+b

After:

def calc(a, b):
    return a + b

Select ALL that apply:

Select all that apply:

Question3 Rule Identification

Which PEP 8 rules were applied in the After version of these imports?

Before:

import sys,os,json
from typing import List,Dict
import numpy as np

After:

import json
import os
import sys
from typing import Dict, List

import numpy as np

Select ALL that apply:

Select all that apply:

Question4 Best Practices

Why is the blank line between import groups important?

import json
import os
import sys
from typing import Dict, List
                                 # <-- this blank line
import numpy as np
Question5 Difference Analysis

How many PEP 8 improvements were made between the Before and After versions?

Before:

class dataProcessor:
    def __init__(self,items):
        self.items=items
        self.count=len(items)
    def Process(self): return [x*2 for x in self.items]

After:

class DataProcessor:
    def __init__(self, items):
        self.items = items
        self.count = len(items)

    def process(self):
        return [x * 2 for x in self.items]

Enter a number:

Question6 Rule Identification

Which PEP 8 naming convention rules were applied in the After version?

Before:

class dataProcessor:
    ...
    def Process(self): return [x*2 for x in self.items]

After:

class DataProcessor:
    ...
    def process(self):
        return [x * 2 for x in self.items]

Select ALL that apply:

Select all that apply:

Question7 Rule Identification

Which PEP 8 rules were applied in the After version?

Before:

camera={'x':0,'y':2.0,'z':1.5}
max_distance=100
default_threshold=0.5

After:

camera = {'x': 0, 'y': 2.0, 'z': 1.5}
MAX_DISTANCE = 100
DEFAULT_THRESHOLD = 0.5

Select ALL that apply:

Select all that apply:

Question8 Best Practices

Why were max_distance and default_threshold renamed to MAX_DISTANCE and DEFAULT_THRESHOLD?

Question9 Difference Analysis

How many PEP 8 improvements were made between the Before and After versions?

Before:

def process(data,threshold=10,debug=False):
    result=[]
    for item in data:
        if item>threshold:result.append(item*2)
    if debug:print(f"Processed {len(result)} items")
    return result

After:

def process(data, threshold=10, debug=False):
    result = []
    for item in data:
        if item > threshold:
            result.append(item * 2)
    if debug:
        print(f"Processed {len(result)} items")
    return result

Enter a number:

Question10 Best Practices

Why is breaking compound statements into separate lines important for debugging?

Before (compound):

if item>threshold:result.append(item*2)

After (separate lines):

if item > threshold:
    result.append(item * 2)
Question11 Difference Analysis

How many PEP 8 improvements were made between the Before and After versions?

Before:

from dash import Dash,html,dcc
import plotly.graph_objects as go
import numpy as np
import sys

def create_visualization(x_data,y_data,title="Plot"):
    fig=go.Figure()
    fig.add_trace(go.Scatter(x=x_data,y=y_data,mode='lines',name='Data'))
    fig.update_layout(title=title,xaxis_title="X",yaxis_title="Y")
    return fig

APP_title="Road Profile Viewer"

After:

from dash import Dash, dcc, html
import numpy as np
import plotly.graph_objects as go

def create_visualization(x_data, y_data, title="Plot"):
    fig = go.Figure()
    fig.add_trace(go.Scatter(
        x=x_data,
        y=y_data,
        mode='lines',
        name='Data'
    ))
    fig.update_layout(
        title=title,
        xaxis_title="X",
        yaxis_title="Y"
    )
    return fig

APP_TITLE = "Road Profile Viewer"

Enter a number:

Question12 Rule Identification

Which categories of PEP 8 rules were applied in the real-world example?

Before:

from dash import Dash,html,dcc
import plotly.graph_objects as go
import numpy as np
import sys

def create_visualization(x_data,y_data,title="Plot"):
    fig=go.Figure()
    fig.add_trace(go.Scatter(x=x_data,y=y_data,mode='lines',name='Data'))
    fig.update_layout(title=title,xaxis_title="X",yaxis_title="Y")
    return fig

APP_title="Road Profile Viewer"

Select ALL categories that apply:

Select all that apply:

Question13 Best Practices

Why is multi-line formatting preferred for function calls with many arguments?

Before (single line):

fig.add_trace(go.Scatter(x=x_data,y=y_data,mode='lines',name='Data'))

After (multi-line):

fig.add_trace(go.Scatter(
    x=x_data,
    y=y_data,
    mode='lines',
    name='Data'
))
Question14 Best Practices

A teammate changes mode='lines' to mode='markers' in a function call. Which formatting style produces a cleaner git diff?

Style A (single-line):

fig.add_trace(go.Scatter(x=x_data, y=y_data, mode='lines', name='Data'))

Style B (multi-line):

fig.add_trace(go.Scatter(
    x=x_data,
    y=y_data,
    mode='lines',
    name='Data'
))
© 2026 Dominik Mueller   •  Powered by Soopr   •  Theme  Moonwalk