Style Point Deductions Starting in HW5

Remember there are "official" Python Style guidelines you can refer to here for more detail. This list is meant to be a quick reminder of specific issues we have seen in homeworks this quarter.

Variable and function naming.

Students shouldn't use single letter names for variables that should really be 'factorial', 'current_sum', or 'reciprocal'. n, i, and j are fine for loop variables.

Space between a function and its parameter list.

Spaces around operators.

Lingering debug code.

Unnecessary nested if statements or a series of if statements

Do this:

if val > 120:
    print "Green!"
 
elif val > 80:
    print "Blue!"
 
elif val > 32:
    print "Red!"
 
else:
    print "Orange!"

Instead of this:

if val > 120:
    print "Green!"
 
else:
    if val > 80:
        print "Blue!"
 
    else:
        if val > 32:
            print "Red!"
 
        else:
            print "Orange!"

Do this:

for base in nucleotides:
    if base == 'A':
        # code here 
 
    elif base == 'C':
        # code here 
 
    elif base == 'T':
        # code here 
 
    elif base == 'G':
        # code here 

Instead of this:

for base in nucleotides:
    if base == 'A':
        # code here 
 
    if base == 'C':
        # code here 
 
    if base == 'T':
        # code here 
 
    if base == 'G':
        # code here 

Looping over the same data multiple times in a row

Do this:

for base in nucleotides:
    if base == 'A':
        # code here 
 
    elif base == 'C':
        # code here 
 
    elif base == 'T':
        # code here 
 
    elif base == 'G':
        # code here 

Instead of this:

for base in nucleotides:
    if base == 'A':
        # code here 
 
for base in nucleotides:
    if base == 'C':
        # code here 
 
for base in nucleotides:
    if base == 'T':
        # code here 
 
for base in nucleotides:
    if base == 'G':
        # code here 

Replicating code from functions that you already wrote

Comenting and docstrings