This question has been asked on SO and an answer was given here. However it doesn’t fully solve my problem as my problem is a little bit more complex.
I have a student’s total score which represents an integer 0 <= x <= 100
. Depending on where the student’s total score lies, a given grade will be issued and some logic will run also.
Of course I could write it like so:
if 0 <= grade <= 39:
do_f()
elif 40 <= grade <= 60:
do_b()
elif 60 <= grade <= 100:
do_a()
You can see the problem with this already. What if more grades are added? It becomes an if else entanglement.
How can I rewrite this using a dispatch table or any other elegant and efficient way?