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 trialSky Lu
1,260 PointsJust want to try another way to get the same result
I just want to find another way to done what the video done but the code is always error, hoping someone can help me:
# ask for new items
user_input_1 = input("What you want to put in the list? ").split()
#why i'm using split, because I want make it from string to list, then i can use extend later
# once user enter anyting, variabe user_input_1 should be True, the interesting thing is if I type "if user_input_1 is True“ it will error "user_input_1 is not defined, so here I have to thought it is False:
if not user_input_1 is True:
user_input_2 = input("Enter 'DONE' to quit this app").split()
# after user entered DONE, add 'DONE' to list user_input_1
if user_input_2 == ['DONE']:
user_input_1.extend(['DONE'])
else:
print("Please enter right word 'DONE'")
# using for loop, once it find 'DONE', it will stop and print out all things
for show in user_input_1:
if user_intput_1 == 'DONE':
break
print(show)
1 Answer
Stefan Plötz
6,237 PointsHi, I think your error happens when your try to compare your users second input with your ['DONE'] list. I put in your code into the console and if user_input_2 == ['DONE'] threw a syntax error. So I cant really explain why it doesnt work but I can offer a solution. You can check for the same thing using
if 'DONE' in user_input_2: etc etc
and likewise for your for loop
Then your code should be somewhat functional even though it will always run only once since there is no way to return to the top without the use of function or a while loop encapsulating the whole thing :) sorry for not formatting my post but I'm currently on the phone.
EDIT: To transform something into a list you can simply use the list() function.