Late Arrival and Lists - What is wrong?


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/1/1?curriculum_id=4f89dab3d788890003000096#


What is wrong?
Oops, try again. Remember: len(list_name) will return the length of a list as an integer.


suitcase = [] 
suitcase.append("sunglasses")

# Your code here!
suitcase.append('shirt')
suitcase.append('bathing suit')
suitcase.append('pants')



list_length = 4 # Set this to the length of suitcase

print "There are %d items in the suitcase." % (list_length)
print suitcase


#2

use len() like the error message suggest, hard coding list_length like you did is considered bad practice. using len() will make your code more robust.

lets say you want to add another item to your suitcase, you might forgot to update list_length, if you would use len(), its done automatically. So your code is less prone to mistakes


#3

Hi, i did list_length = len("suitcase") # because here we can put the length of suitcase for list_length
and if you put more "objets" in your suitcase the length can change.
l
print "There are %d items in the suitcase." % (list_length)

There are 4 items in the suitcase.


#4

Codemaster55976 is right


#6

The solution is pretty much in this topic? If it doesn't suit you, please make a new (linked) topic like stated in the guidelines and don't hijack an existing topic


#7

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