I need help with a module I am making

I am making a module that encrypts your number/letters and I am working on a decrypting part and I make it so that it has two keys it needs to do the math and when I do a for loop and I directly take it from the function I says it isn’t a integer if there is a way to fix it please help
here is my source code (Btw this is my first module for python):

class decoder:
    def numbers(nkey, okey, encrypted_number):
        for i in range(nkey):
            output= encrypted_number/okey
        return output

you have defined the numbers function in a class, which makes it a method.

methods automatically have the instance of the class passed as the first parameter – usually called “self” by convention. So in this case, nkey is getting set to an instance of the decoder class, which is why it’s not an integer.

That should be:

class decoder:
    def numbers(self, nkey, okey, encrypted_number):
        for i in range(nkey):
            output= encrypted_number/okey
        return output

However, why is it in a class, and not a simple function? it that case, simply:

def numbers(nkey, okey, encrypted_number):
    for i in range(nkey):
        output= encrypted_number/okey
    return output

Would work just fine.

.
.
.
NOTE: another option is to make it a staticmethod – but there’s not often a good reason to do that in Python – save that for more advanced usage :slight_smile:

1 Like

thank you, so much