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 trialmohan Abdul
Courses Plus Student 1,453 Pointsthe teacher he could have added '''add_to_list''' to an else statement, but it meant that he wouldn't able to show me t
the teacher he could have added '''add_to_list''' to an else statement, but it meant that he wouldn't able to show me the '''continue''' function. Can anyone please show me it would have looked like if the teacher used else statement please?
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsBy extending the if
statement with the code:
else:
add_to_list(new_item)
the if
statement becomes the last code within the while
block. Therefore it will not matter if the continue
statements remain. In either case, the code will jump back to the top of the while
loop. Since, it doesnβt matter, the continue
statements should be removed to simply the code.
Post back if you need more help. Good luck!!!
mohan Abdul
Courses Plus Student 1,453 Pointsmohan Abdul
Courses Plus Student 1,453 Pointsin your python code, could you please include were break and continue would have been. I'll copy and paste the code here so save you from typing it from scratch.
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsOriginal code:
becomes
mohan Abdul
Courses Plus Student 1,453 Pointsmohan Abdul
Courses Plus Student 1,453 Pointshi, on both the ''elif'' statements its missing the key word '''continue''', on typing '''SHOW''' & '''HELP''' wouldn't it add SHOW & HELP onto the list? As in the original code with out continue it added them to the list.
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsIn an
if/elif/else
statement, only exactly one code block will execute. Since the add is in theelse
block, it will only execute if none of the preceding conditions are met.The next line to execute after
show_help
orshow_list
will be thewhile
statement.