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!
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
Yessica Schoonen1,553 Points
Task 1 TypeError
I keep getting typeErrors.. I'm having a hard time grasping remembering what I've learnt from the videos. Someone any tips for me?
def just_right(): string =  while len (string) < : try: length = int(input("You string is too short")) except ValueError: print("Your string is too long") string.append(length) just_right()
Krishna Pratap Chouhan15,203 Points
Lets go through the question and we'll solve the task and learn while doing that.
create a new function
the function takes a single argument
if length of argument is less than five, return...
if len(string_argument) < 5: return "Your string is too short"
if length is more than 5 return ...
elif len(string_argument) > 5: return "Your string is too long"
other wise return true
return True #OR since the program-control will come out of if&elif, in case the length of string is 5 so doesn't matter if we return through else or through the program, Right? else: return True
Final Solution(remember the indentation)
def just_right(string_argument): if len(string_argument) < 5: return "Your string is too short" elif len(string_argument) > 5: return "Your string is too long" return True
def just_right(string_argument): if len(string_argument) < 5: return "Your string is too short" elif len(string_argument) > 5: return "Your string is too long" else: return True
Now lets call the function: just_right("123456")
And hard time while learning and remembering??? it quite common, don't stress yourself. give it time :) You already are smart that you opted for Python, i started with C/C++ and i couldn't understand a thing for a year.
!Dont tell that to my manager =D. Enjoy coding.
Hope this helps!