1
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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] <> "?"]
$\endgroup$
1
  • $\begingroup$ Thank you so much! I knew there was a simple solution that I would never figure out on my own. $\endgroup$
    – Benjamin
    Commented Oct 9, 2013 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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