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 trialdouglas gray
888 PointsGeneral technique and a program that won't run.
Hey everyone! My first question is could anyone guess some reasons that my program simply won't run? When I try to run it in the shell it acts as if it is running but no list of vowel free states appears. When I tinker with the above script and re-run it I get error messages I expect, so maybe it is reading it. Could it be that my last two lines-- "output.append....." and "print (output)" aren't arranged correctly? As i understood it they could run outside the while loop, but I tried putting them in it just in case.
Something related that I was wondering about was, how might I understand Pythons treatment of each of the state names in the original name list? I see the program iterates through the vowel list and removes them from the state_list, but why doesn't it need a separate command to iterate through the entire state_list since it's made of many items?
My apologies if any of that is convoluted. This is still foreign to me. Thanks for any insight!
Jeremy Hill
29,567 PointsIf you can post your code we might be able to see what is wrong with it.
3 Answers
Steven Parker
231,108 PointsAs the others mentioned, you should post the code you would like specific help with.
But for your other question, the program does not need a loop to iterate through state_list because the remove method will take away the vowels no matter where they are in the list. In a sense, remove is the command you are expecting.
douglas gray
888 PointsHey there! My code is as follows:
State_names = [California, Florida, Oklahoma] vowels = [aeiou] output = []
for state in State_names: State_list = list(state.lower())
for vowel in vowels:
while True:
try:
State_list.remove(vowel)
except:
break
output.append(''.join(State_list).capitalize())
print(output)
I keep getting an error message saying that the states in State_names aren't defined.
douglas gray
888 PointsOf course. Thank you, Steven. Now it prints a list of states but with the vowels still in them. Do you know the best way to share a snapshot of the workspace here in this forum?
Jeremy Hill
29,567 PointsYou should probably put some quotes or something around your Strings in your State_names list. Maybe do the same with your vowels variable.
Jeremy Hill
29,567 PointsI tweaked your code to make it run, I didn't fix any logic errors if any, but here is the code that runs:
State_names = ['California', 'Florida', 'Oklahoma']
vowels = ['a','e','i','o','u']
output = []
for state in State_names: State_list = list(state.lower())
for vowel in vowels:
while True:
try:
State_list.remove(vowel)
except:
break
output.append(''.join(State_list).capitalize())
print(output)
douglas gray
888 Pointsdouglas gray
888 Pointsi meant, i get error messages, so i know it is reading it.