Intro to python, exercise 14.zzz


#1

Hi, I been stuck for a while for with this exercise but i finally came up with this code which give me lots of errors, the funny thing is, i was allow to move the next stage of the exercise.
Your job: Use a for loop to print out only the words that start or end with the letter “z”.

words = [“pizazz”, “python”, “zebra”, “pizza”]
word = words
for word[0:]in words:
print(word)
Unknown Error: , ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘i’, ‘p’, ‘i’, ‘z’, ‘a’, ‘z’, ‘z’, ‘pizazz’, ‘python’, ‘zebra’, ‘pizza’] this is the error i got but i’m allow to move on which is strange. I want to move on the right so can someone help me with the rightful code?


#2

This is not creating a copy of the list, only a reference to it. To copy a simple, flat list, use slicing

word = words[:]

Now your copy will be an actual list, not a reference to the other one.

Not really sure what the objective is here…

for word[0:]in words:

In truth, we do not need a copy of the list since we are only iterating over it.

for word in words:
    if word[0] == 'z' or word[-1] == 'z':
        print word

#3

Thanks for the info. mtf


#4

headlines = [“Man Takes First Steps on the Moon”,
“Titanic Sinks Four Hours After Hitting Iceberg”,
“Dewey Defeats Truman”,
“Greatest Crash in Wall Street’s History”]

maximum_headline_length = 35
for headline in headlines:
if headline > maximum_headline_length:
print headline
else:
print(“reject”)


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.