Can't find a mistake


#1


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

Your code here!

suitcase.append("clothes")
suitcase.append("camera")
suitcase.append("passport")

list_length = len(suitcase) # Set this to the length of suitcase

print "There are %d items in the suitcase:%d" % list_length, suitcase
print suitcase

In this case, I want to list all items in suitcase in ''There are %d items in the suitcase:%d", instead of printing separately.
But it says my code is wrong.
Are there any way?


Replace this line with your code.


#2

This line is creating an error
print "There are %d items in the suitcase:%d" % list_length, suitcase

Explanation - how to insert values inside a string!
One example!

x =  100

"I have scored %s marks in history."

to insert 100 (value of x) I 'd do this..

print "I have scored %s marks in history." % (x)

If I have more than one variable...

geography = 70
maths = 67

"I have scored %s in geography and %s in maths"

I'd do something like this...
print "I have scored %s in geography and %s in maths" % (geography , maths)

It will print this--
I have scored 70 in geography and 67 in maths

Note: order is important.
This is how we use string identifier to put values inside a string!
Notice the parentheses [after % ] that carries all values, separates them using commas?


#3

Thanks! :slight_smile: Now my code works:

print "There are %d items in the suitcase:%s" % (list_length, suitcase)


#4

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