I have a script from a python class designed to check answers against a server that seems a bit cumbersome and I am trying to see if there is a better pythonic way of doing this.
I have a ton of tiny functions that perform quick operations, they are numbered due to the potentially high number of questions to be answered in the class (example, not live code):
def function_1(data):
return data + 1
def function_2(data):
return data**100
def function_n(data):
return ((data + 2) * 4) // 16
and in the main function, it essentially prints out the output of those functions
def main():
input = "20"
print("#1", exercise.answer(1, function_1(input)))
print("#2", exercise.answer(2, function_2(input)))
print("#n", exercise.answer(n, function_n(input)))
I have been trying to see if there is a way to print the functions sequentially using a loop, something like this:
i = 1
while i < n+1
print("#" + str(i), function_i(input))
This way I only have to add a new function up top, and increase the number n
in the while
loop, while also reducing the number of prints in the code itself. Any pointed direction would be helpful.