Thanks for your suggestion.
Although I didn't understand why your code worked so, I confirmed your sub worked in an expected way.
I didn't consider whether to normalize users' inputs.
In my case, "be strict with your output" points out the following: