Entering data with Input[] in mathematica

2020-07-27 04:14发布

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];
]

2条回答
Emotional °昔
2楼-- · 2020-07-27 04:28

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.)

查看更多
姐就是有狂的资本
3楼-- · 2020-07-27 04:47

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:

enter image description here

查看更多
登录 后发表回答