views:

85

answers:

1

The question i'm working on asks me to "write an expression whose value is the concatenation of the three str values associated with name1 , name2 , and name3" , separated by commas." "So if name1 , name2 , and name3 , were (respectively) "Neville", "Dean", and "Seamus", your expression's value would be "Neville,Dean,Seamus". "

The answer that i submitted is "name1,name2,name3" but when i click "submit" the message informs of a logical error within my code and that my expression didn't return the correct value. What have i done wrong?

+3  A: 

Homework? Did you submit the result of the expression, or the expression itself?

",".join([name1, name2, name3]) Or whatever you used?

Edit: You mention that you submitted ("name1", "name2", "name3") - which would not return the concatenated names - but rather those stings. If you wanted to do it like this (a little less elegant then the version I put above) you could try:

name1 + "," + name2 + "," + name3

The difference being the quotations (") around the names - are stopping you from using the variables provided.

Edit2: This is how I understand the question you were asked. They want you to submit to them, an expression that will return the values assigned to the name1, name2 and name3 variables (whatever they may be) - There are two examples of such expressions above - which concatenate the three name variables, and add a comma between them - have you tried submitting either of the examples above?

Tim
i probably indeed submitted the result of the expression when i should've submitted the expression itself. However, even when i made the appropriate changes i.e. i changed my answer to "("name1," + "name2," + "name3")", i still get an error. i tried it all sorts of different ways and it's not working. I typed my solution in the command line and it worked there..?
Frens34
`"name1, " + "name2"` will output the string `name1, name2` where your question expects Neville, Dean. You need to use `name1 + ", " + name2`
Tom Leys
sorry, i'm not exactly sure what you mean? "Neville, Dean and Seamus" are just an example for this question.
Frens34
@Frens34 - Edited post to answer your question.
Tim
Awesome Tim. the second example worked- thank you.
Frens34