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 trialAdam Beltz
4,134 PointsDifferent methods, same result.
Instead of using a while loop, I called the function again (from within the function) if the input did not equal "DONE". I also printed from within the function rather than after a break. Is either method preferred / better for each of these two differences?
list = []
def taskl():
task = input("What would you like to add?")
if task != "DONE":
list.append(task)
taskl()
else:
print(list)
taskl()
1 Answer
Bartosz Pająk
7,369 PointsIn this case there is no difference, so you should use the one that is more clear or easier. But when you call a function from itself(recursive functions) sometimes it may get tricky so you should definitely be careful and analyze what your code actually does when you're using recursive functions.
Adam Beltz
4,134 PointsAdam Beltz
4,134 PointsThank you.