Entering data with Input[] in mathematica

自作多情 提交于 2019-12-06 10:35:56

问题


How can i make in this code the text in Dialog Box of the Input command to be like this "Enter the 1 element","Enter the 2 element"....

For[k = 1, k ≤ n, k++,
  br = Input["Enter the ",i,"element"];
  AppendTo[x, br];
]

回答1:


Make sure your variables match. :-)

You can use Row to build up the text.

x = {};
n = 3;
For[k = 1, k <= n, k++,
 br = Input[Row[{"Enter the ", k, " element"}]];
 AppendTo[x, br];
 ]

(You could also use StringJoin["Enter the ", ToString[k], " element"], but I like Row better.)




回答2:


According to the Input[ ] help:

The prompt given can be text, graphics or any expression.

So, anything will fit in the input prompt!

Just as an example (note the explicit loop is not needed):

x = Input[
    Panel[Grid@{{Row[{"Enter the element number ", #}]}, 
                     {PolyhedronData["Platonic", {"Image"}][[Mod[#, 5] + 1]]}}]
         ] & /@ Range[1, 5]

Will show things like:



来源:https://stackoverflow.com/questions/5427784/entering-data-with-input-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!