This post seems relevant to your problem. Briefly:
- You only need 1
$ans
column and it should be the string number (e.g.,'1'
,'2'
). - After reading the keyboard response, add a code component to “clean up” the key response, similar to the solution in the linked post. In essence, if the key response is kept in a variable called
key
, then only retain the last char of the array. As a result, ffkey = '2'
, thenkey[-1] = 2
, and ifkey = 'num_2'
, thenkey[-1] = '2'
.