Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,639 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,494 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.