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 trialKonstantin Krumov
3,117 PointsWhy is my code not accepted by the site, when it works in my terminal ?
I am currently running python 3.0 on my laptop and the code is running fine, however the site does not accept my answer.
# E.g. word_count("I do not like it Sam I Am") gets back a dictionary like:
# {'i': 2, 'do': 1, 'it': 1, 'sam': 1, 'like': 1, 'not': 1, 'am': 1}
# Lowercase the string to make it easier.
def word_count(string):
string = string.lower()
dictionary = {}
for word in string.split(' '):
if word in dictionary.keys():
dictionary[word] += 1
else:
dictionary[word] = 1
return dictionary
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi Konstantin,
A good rule to remember: even if it works on your machine, does not mean that it satisfies the requirements of the challenge and it's code checker.
Here, all you code is syntactically correct However... you should be splitting on all whitespace not just spaces.
I was positive that at one point, this was explained in the instructions, but not anymore. If you just change your split()
method to split on all whitespace, the challenge does pass.
Hope this helps and Great Job so far!! :)
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsAh... if you run your code in the code checker, you will get the error that states
"Be sure you're lowercasing the string and splitting on all whitespace!"
I knew I saw the "all whitespace" somewhere. :)
Konstantin Krumov
3,117 PointsKonstantin Krumov
3,117 PointsThank you very much for the quick and valuable feedback. Will pay more attention in future.
As silly as it may seem I had no idea white spaces was different from spaces.