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 trialMohamed Mohamoud
1,015 Pointsis this code not right?
i put this code into the workspace and it works, but when i use it in the website it don't work. what im i doing wrong?
def just_right(x):
while len (x) < 5:
print("your string is too short")
if len (x) > 5:
print("your string is too long")
else:
return True
just_right("games")
1 Answer
Gianmarco Mazzoran
22,076 PointsHi,
You got an error because you print()
the messages instead of return
.
def just_right(x):
while len(x) < 5: # pay attention for the space between the function and the parenthesis
return "your string is too short"
if len(x) > 5: # pay attention for the space between the function and the parenthesis
return "your string is too long"
else:
return True
just_right("games") # you don't need to call the function
Mohamed Mohamoud
1,015 PointsMohamed Mohamoud
1,015 Pointsyh it works, thanks.
the reason i printed instead of returning is because there was another activity like this and it wasn't allowing to return, but it worked when i used print.
i must have misread it.
thanks!!!!!