Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Technical Interview Prep: Python Basics Basic Python And I Will Try To Fix You

I've checked the guidelines for PEP8 and I cant seem to find anymore problems could you please help me. Thank you.

I've checked and I can't seem to find more problems could you please help me find anything I'm missing

pep.py
import datetime


def my_func():
    return "It ran!"


sizes = ["small", "medium", "large"]


class Tree:
    def __init__(self, size, characteristics):
        self.size = size
        self.charac = characteristics
        self.roots = True
        self.leaves = 0


    def grow_leaves(self):
        self.leaves += 1


Tree (sizes[ 0 ], {"name": "Tulip Tree"})

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Danielle Murray, there is a Python module pycodestyle available to check this. This module was formerly know as "pep8".

Output is file:line:char: Error or Warning number message

(venv)$ pip install pycodestyle

(venv)$ pycodestyle dmurray_pep8.py 
dmurray_pep8.py:19:5: E303 too many blank lines (2)
dmurray_pep8.py:23:5: E211 whitespace before '('
dmurray_pep8.py:23:13: E201 whitespace after '['
dmurray_pep8.py:23:15: E202 whitespace before ']'

Edit: There's also the Python module black that will auto-correct these errors:

(venv)$ cp dmurray_pep8.py dmurray_pep8_org.py
(venv)$ black dmurray_pep8.py 
reformatted dmurray_pep8.py
All done! ✨ 🍰 ✨
1 file reformatted.
(venv)$ diff dmurray_pep8.py dmurray_pep8_org.py 
17a18
> 
22c23
< Tree(sizes[0], {"name": "Tulip Tree"})
---
> Tree (sizes[ 0 ], {"name": "Tulip Tree"})

EDIT: I forgot to mention that the challenge checker incorrectly requires single quotation marks (') instead of double quotations marks ("). This is not a standard practice and many standard formatting programs (such as black) use double quotation marks. This has been brought to the attention of the dev team to no avail.

Dev Team: change the passing conditions to include double quotations.

Post back if you need more help. Good luck!!

Hi Chris Freeman thank you so much for your help but after fixing all my errors that you mentioned above i'm still getting an error mentioning that functions and classes need 2 spaces. import datetime

def my_func(): return "It ran!"

sizes =["small", "medium", "large"]

class Tree: def init(self, size, characteristics): self.size = size self.charac = characteristics self.roots = True self.leaves = 0

def grow_leaves(self): self.leaves += 1

Tree(sizes[0], {"name": "Tulip Tree"})

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

See edited answer above. TL;DR: the challenge only accepts single quotation marks, not double.

It's not a correct requirement and some style guides are expressly against using single quotations everywhere. A string with a contraction single apostrophe would break the single quotation paradigm.

Chris Freeman

import datetime

def my_func(): return 'It ran!'

sizes =['small', 'medium', 'large']

class Tree: def init(self, size, characteristics): self.size = size self.charac = characteristics self.roots = True self.leaves = 0

def grow_leaves(self): self.leaves += 1

Tree(sizes[0], {'name': 'Tulip Tree'})

I've changed all of the quotation marks to single quotation marks but it still does not pass and gives the error message that the quotation marks need to be consistent.

Instead of sizes =['small', 'medium', 'large'], try sizes = ['small', 'medium', 'large'] with a space after the =.

There is another issue with this challenge. I was receiving blank line errors, i.e. "there should be a blank line after a method" or "There should be 2 blanks lines after a function or class"

The online editor was inserting spaces when hitting return after function or method definitions. It was considering these lines not empty. I had to manually delete the spaces without removing the blank line before the tests passed. Frustrating

import datetime


def my_func():
    return 'It ran!'


sizes = ['small', 'medium', 'large']


class Tree:

    def __init__(self, size, characteristics):
        self.size = size
        self.charac = characteristics
        self.roots = True
        self.leaves = 0

    def grow_leaves(self):
        self.leaves += 1


Tree(sizes[0], {'name': 'Tulip Tree'})
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Ryan Valentine, that is frustrating! Good feedback, unfortunately, the challenge editor is used across many languages and doesn't have a full-on Python specific mode. That increases the necessary diligence to pass this challenge, but indirectly further reinforces the PEP details (so Win?). Many external editors will have a python-mode that allows one to set "auto-remove trailing white space" so it shouldn't be an issue down the road. Good luck!!