Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to prompt a user to input an answer to a question. I want the question that pops up to have both text and numbers or strings. For example, if I ask the user to give a name to something in the first question, I want the next question to include that name as part of the question itself.

For example, I can prompt the user to name an element,

name=InputString["What is the name of your material?"]

I want the next input to be something like the question, "What is the molar weight of name?", where "name" is the input from the previous question. If the argument for Input[] were similar to Print[], it would look something like,

Input["What is the molar weight of ",name,"?"]

But this does not work because Input[] treats this as three different arguments, delimited by commas. Any thoughts?

share|improve this question
up vote 2 down vote accepted

You have to use StringJoin. In other cases you might also need to convert your variable into a string using ToString.

name=InputString["What is the name of your material?"]
Input["What is the molar weight of " <> ToString[name] <> "?"]
share|improve this answer
Thank you so much! I knew there was a simple solution that I would never figure out on my own. – Benjamin Oct 9 '13 at 18:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.