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 trialtyler bucasas
2,453 Pointsshopping_list3
import os
# make a list to hold onto our items
shopping_list = []
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
# print out instructions on how to use the app
print("what kind of shit is should i put on this list?")
print("type in the word 'Dunn'to end list.")
def show_list():
clear_screen()
print("heres ya got dam list")
index = 1
for item in shopping_list:
print("{}. {}".format(index,item))
index += 1
print("-"*10)
def show_help():
clear_screen()
print (" Enter 'HELP' for show commands")
print (" Enter 'Dunn' to end list")
print (" Enter 'SHOW'to see list")
# add new items to our list
def add_to_list(new_item):
show_list()
if len(shopping_list):
position = input("Where should I add {}?\n"
("Press Enter to add to the end of list\n"
">".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list.insert(position -1, item)
else:
shopping_list.append(new_item)
show_list()
# ask for new items
while True:
new_item = input("> ")
add_to_list(new_item)
# be able too quit app
if new_item.upper() == 'DUNN' or new_item.upper == 'QUIT'
break
# type "HELP" to see msg about the commands
if new_item.upper == 'HELP':
show_help()
continue
# type "SHOW" to see list
elif new_item.upper() == 'SHOW':
show_list()
continue
else:
add_to_list(new_item)
# print out the list
print("here's the motherfuckin list")
for item in shopping_list:
print(item)
I keep receiving a syntax error : invalid syntax on line 40 for the word "else". I'm having a really hard time figuring out whats wrong, someone please help
tyler bucasas
2,453 PointsOszkár Fehér, im not sure how to put it in 1 file. what should i do?
2 Answers
Oszkár Fehér
Treehouse Project ReviewerSo there is a few typos
import os
# make a list to hold onto our items
shopping_list = []
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
# print out instructions on how to use the app
print("what kind of shit is should i put on this list?")
print("type in the word 'Dunn'to end list.")
def show_list():
clear_screen()
print("heres ya got dam list")
index = 1
for item in shopping_list:
print("{}. {}".format(index,item))
index += 1
print("-"*10)
def show_help():
clear_screen()
print (" Enter 'HELP' for show commands")
print (" Enter 'Dunn' to end list")
print (" Enter 'SHOW'to see list")
# add new items to our list
def add_to_list(new_item):
show_list()
if len(shopping_list):
position = input("Where should I add {}?\n"
("Press Enter to add to the end of list\n" <--- Here is an opening bracket which is not needed>
">".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list.insert(position -1, item) <---- I think here it should be new_item instead of item>
else:
shopping_list.append(new_item)
show_list()
# ask for new items
while True:
new_item = input("> ")
add_to_list(new_item)
# be able too quit app
if new_item.upper() == 'DUNN' or new_item.upper == 'QUIT' <---- Here it's missing : and () from upper()>
break
# type "HELP" to see msg about the commands
if new_item.upper == 'HELP': <---- Here it's missing the ()>
show_help()
continue
# type "SHOW" to see list
elif new_item.upper() == 'SHOW':
show_list()
continue
else:
add_to_list(new_item)
# print out the list
print("here's the motherfuckin list") <----Nice touch, just a tip, the Treehouse moderators monitor >
<these and they may say something about it, make sure when you >
<upload something to not contain something which conflict with Code of Conduct>
for item in shopping_list:
print(item)
The logic it's still need work, it adds to the list even the "quit" or "dunn", in this case, to the list. But overall nicely done. Keep up the good work and happy coding.
tyler bucasas
2,453 Pointsthank you i really appreciate it Oszkár Fehér. btw my bad about the swearing i completely forgot that was there LOL
Oszkár Fehér
Treehouse Project ReviewerWhere you write your post under the window is a reference to "Markdown Cheatsheet ", if you click on it will show you what to do. Next to the "1" key on (English) keyboard, on the left side there is a key like `, it's a small wave like symbol, so u use 3x of that ` under you paste your code how it is in your editor and under the code you will close with another 3x ` There is an eye on the right, down side of this post window and you can see how it will look after posting.
tyler bucasas
2,453 Pointsalright I put it all in 1 file, I really appreciate the help Oszkár Fehér
Oszkár Fehér
Treehouse Project ReviewerOszkár Fehér
Treehouse Project ReviewerHi Tyler. Please can you upload all the code in 1 file so i can see the same line like you.