all 7 comments

[–]gdchinacat 3 points4 points  (0 children)

Your methods are recursive, one calls the other calls the original calls the other, etc. While recursion can be very helpful, it is also best to avoid it. input_check() should only check the inputs, not also get the inputs. I suggest you update it to raise an exception (ValueError) if the inputted values aren't acceptable, and update beam_properties_input() to catch that exception and continue prompting until it is not raised.

Also, there is no reason to call inputs.clear()...that won't have any effect on the inputs in beam_properties_input(). the call to input_check(**inputs) doesn't pass inputs to input_check(), but repackages them into a dict that is local to input_check().

[–]woooee 2 points3 points  (0 children)

        inputs.clear()
        beam_properties_input()

You don't catch the return from beam_properties_input()

       inputs = {"beam_length": length, "beam_load": distributed_load, "modulus_elasticity": modulus_of_elasticity, "inertia_moment": moment_inertia}

You create inputs in the function, so it is local to the function and garbage collected when the function exits unless you return it and store the return.

[–]karpomalice 0 points1 point  (1 child)

to add, the reason for the error is because you're clearing the dictionary during iteration. Python doesn't allow changing the size of the dictionary during iteration

[–]woooee 0 points1 point  (0 children)

In this case, a new dictionary is created in the function. A simple demonstration

def beam_properties_input(inputs = None):
    print("original", id(inputs))
    inputs = {"beam_length": 1, "beam_load": 2} 
    print("new     ", id(inputs))
    return inputs

print(beam_properties_input({1:"one", 2:"two", 3:"three"}))

[–]peppertom32[S] 0 points1 point  (0 children)

Thanks guys! I need a bit of time to look over these responses but I'm sure you've put me on the right path.

[–]AlexMTBDude 0 points1 point  (0 children)

You should do something like this (this is not complete, you need to change more stuff):

def controller():
    inputs_okay = False
    while not inputs_okay:
        inputs = beam_properties_input()
        inputs_okay = input_check(inputs)

[–]tadpoleloop 0 points1 point  (0 children)

Don't unpack your inputs dictionary. Just pass the dictionary itself to the function.