I could use some help on Late Arrivals & List Length plz


#1

this is what i got

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

Your code here!

suitcase = "sunscreen"
suitcase = "hat"
suitcase = "bathing suit"

list_length = "singlasses" # Set this to the length of suitcase

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


#2

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

Your code here!

suitcase = "sunscreen"
suitcase = "hat"
suitcase = "bathing suit"

list_length = "singlasses" # Set this to the length of suitcase

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


#3

Hi @alexanderweaver,

There are 2 main problems:

  1. appending items into the suitcase list

The original code gave an example of how you can add items into the empty suitcase list, which is by:

a.k.a. using the list_name.append("item") function. So subsequently when you are adding sunscreen, hat and bathing suit to suitcase, shouldn't you follow this method as well? It doesn't make sense to reassign suitcase to a string for each and every item that you want to add.... :stuck_out_tongue:

2.. length of suitcase

As your comment mentioned, you are supposed to set list_length to the length of suitcase, which really means the number of items in the suitcase list. Relook the example code given, and try to spot a function which can help you to achieve this!

Hope this helps!


#4

i dont get it????????


#5

thats really confuseing


#6

@alexanderweaver,

Let us take a look at the instructions:

  1. On lines 5, 6, and 7, append three more items to the suitcase list, just like the second line of the example above. (Maybe bring a bathing suit?)

  2. Then, set list_length equal to the length of the suitcase list.

So the first thing which you've gotta do is to append 3 more items to the suitcase list, just like how the example did it. So how did the example do it?

letters.append('d')

which should lead you to realise that when adding items to a list you can do list_name.append("item"). For instance, in the example the list name was letters, and they wanted to add the letter 'd' to the list letters, so they did letters.append('d'). Now, you have a list called suitcase, and you want to add bathing suit. What can you do? Do the same for all other items you want to add to suitcase.

Then the second thing we've gotta do is to set the variable list_length equal to the length of the suitcase list. How? Again, we can refer to the example code:

len(letters)

When they wanted to find the length of the list letters, they simply used the len() function, by doing len(list_name). In this case, your list name is suitcase, so how can you modify this function so that it will calculatethe length of the suitcase list for you?


#7

i got it thx for the help


#8

you're welcome! :slight_smile:


#9

After running a search to find elaboration on this exercise I came across this thread and it helped a bunch. Thanks and on too the next!


#10

Basically I just had to separate each append argument, instead of trying to combine them onto one line separated by commas.

E.g. suitcase.append("bathing_suit")
suitcase.append("sunscreen")
suitcase.append("sandals")