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 Introducing Lists Build an Application Add Items

Michael Casella
Michael Casella
1,358 Points

Why was add_to_list in the while loop not an else statement?

Why was add_to_list in the while loop not an else statement?

2 Answers

Steven Parker
Steven Parker
229,786 Points

An "else" is not needed there since both the "if" and "elif" conditions change the program flow, so all the code below them is done only in an "else" condition. This is a common technique to make the code more compact and easier to maintain.

Shanil Mohan R
Shanil Mohan R
1,506 Points

Like steven mentioned else is not needed here to keep the code more readable and compact. But you are right. There is no harm in putting the add_to_list function in an else block.