"Assign a variable to a value" or the other way round?
Assign a value to a variable is correct. Alternatively, you could say assign a variable a value.
Compare assign and give:
Give a value to a variable vs. give a variable a value
You want "assign a value to a variable"; it is the variable that is receiving the assignment of something. Think of the same sentence with "price" for "value" and "commodity" for "variable"; you assign a price to a commodity but not the other way around.
A variable is a quantity that may represent any one of a set of values. So you assign a value to a variable. The second one is correct.
Assign a value to a variable. The confusion may arise from the fact that you can correctly say assign a variable a value, which has the same meaning.
Being a math teacher, I immediately began running my classroom dialogue through my head looking for common usage (which of course isn't always correct usage).
So, from the trenches, we say "Assign a value to a variable."
When we take a value, assign it a variable name so we can look at behavior for all possible values, we call that a parameter, rather than a variable.
However, we don't typically assign values to variables. Rather we define variables to represent quantities, and then solve for values of interest under the given conditions.
NOTE: I recognize that the StackExchange is for providing answers, rather than getting into discussions. I offered the above in case @pimvdb was writing in/about an unfamiliar field and could benefit from some "insider" knowledge. If the moderators need to delete this, that won't bother me.