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 trialJustin Kinney
445 Pointsso I built a side project to help my self with list and while/break. Well I ran into a problem can someone debuf this?
new_list = list()
print('list your siblings once finished type "done" to exit prompt')
while True:
new = input("sibling name: ')
if new == "done":
break
new_list.append(new)
print('tell {} computer says Hi'.format(new_list))
can some one help please?
4 Answers
Justin Kinney
445 Pointsokay changed that thnx for pointing it out, but nw it says SyntaxError: 'break' outside loop
Ron Fisher
5,752 PointsRemember that each block of code has a colon to start it and then each statement below it should be indented if it is part of that block.
To the interpreter, you have 2 different blocks of code and not one. The 'if' statement starts at the far left and so does the 'break'. If you indent the 'break' it will be interpreted as part of the 'if' block.
Justin Kinney
445 Pointsohhh okay
karan
1,071 PointsI believe - new_list.append(new) should be before the if statement. This should print the names of all the siblings with the last print statement.
ryankite
8,265 PointsI'm very new to python by I think the "continue" keyword was also missing at the end of the if statement, when running Justin's code above ( with the adjustments from Ron ), when printing the list it was only printing the string "done", as if that was the only item in the list, below is a slightly modified version that seems to work.
sibling_list = list()
print('Please list your siblings once finished type "DONE" to exit the prompt')
while True:
sibling = input("sibling name: ")
if sibling == "DONE":
break
sibling_list.append(sibling)
print("Sibling added! So far you have {} siblings.".format(len(sibling_list)))
continue
print ("Here are all the Sibling on your list:")
print('Be sure to tell ' + ', '.join(sibling_list) + ' that the computer says Hi.')
Ron Fisher
5,752 PointsRon Fisher
5,752 PointsYour
while True: new = input("sibling name: ')
input statement opens with a double quote and ends with a single quote. They must match so the parser knows the difference between items that are apostrophe's and beginning and ends of quoted strings.