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 Python Basics Functions and Looping Raise an Exception

Hm. I'm not exactly sure how to do this.

Well I used my notes from Workspaces to create this code, however I kind of knew this probably wouldn't work as I didn't mention character length in the "if" statement. I feel I'd have this correct if it was just about numbers though, but obviously this isn't just about numbers and I'm not sure how to fix this.

suggestinator.py
def suggest(product_idea):
    if product_idea < 3:
        raise ValueError("Idea needs to be 3 or more characters long")
    return product_idea + "inator"

2 Answers

Eric M
Eric M
11,546 Points

Hi Sean,

You've correctly identified the problem, great work! We can get the character length of a string by using the len() function. e.g. len(product_idea)

When you know the problem don't be afraid to google! For instance here a quick "get length of a string python" could have probably given you the answer. Most professional programmers will do a google search like this multiple times per day. I do this a lot!

Cheers,

Eric

Thank you! I appreciate it! I'll put you down as Best Answer. I actually googled this problem and found it was asked and answered on here already, but I'm really glad you were so quick to help out.

Eric M
Eric M
11,546 Points

That's great! Glad to hear you're already off solving problems on your own. Best of luck with the rest of the Python courses, I think they're really good.

I don't know if I'd call it solving it on my own if I still had to look it up. What I'm afraid is what if I can't actually solve these issues on my own? I wouldn't be hired to work in this industry if I always needed help.

Eric M
Eric M
11,546 Points

You'll want to be able to write a lot of code from memory in your language of choice, but if you're solving interesting problems you're probably running up against things you've not tackled before.

Also, even experienced programmers make heavy use of reference materials both in books and online.

Sure you probably won't be looking up len() but you might be looking up whether a method for a third party API takes an array of key value pairs or an array of tuples. Or you might forget if something is a builtin function or part of a library you need to import, so you google the function name to check. If you're using regex, you'll probably want to use a reference because it's so arcane unless you do it constantly. If you're a front end web developer you'll use CSS cheat sheats and the MDN a lot. You'll probably look at them less if you do the same thin every day, but you'll still want them available.

Don't be afraid to look at the docs! I've done coding challenges in job interviews where they've given me a laptop and said "finish this task, feel free to use google, stack overflow, whatever, we just want to see where you can get to in an hour".

There's a reason the docs are in the teachers notes. This is complicated stuff!

Edit: In regards to being able to solve issues on your own. You should be able to identify the logic a program needs to execute in order to achieve a result, but remembering every minutae of language syntax is not a requirement for being a great programmer. The more you remember the better of course, but if you can devise a solution and then use the docs to put the solution together, believe me, there's work out there and the more you do it the better you'll get.