Python Object-Oriented Python Advanced Objects Double

Chiroi Niehus
Chiroi Niehus
6,729 Points

I Am Having Trouble on Code Challenge: Double Task 3 of 3

I am having trouble figuring out whether it should be self or int that I multiply by 2. Also, I'm not sure where to put the two separate lines of code - inside the function, or in the class. Please help!

doubler.py
class Double(int):
    def __new__(*args, **kwargs):
        self = int.__new__(*args, **kwargs)
        return self

    doubled_value = self * 2
    return doubled_value

1 Answer

Kamaren McCord
Kamaren McCord
11,209 Points

It looks like you want to put the code for the *double * inside of the new method. If you put it outside of this method the code will not be ran and thus will not return self * 2 when created.

self is an int so take self and multiply by 2, then return self.

also keep in mind that you cannot return code after a return has already been made. so you cannot use double return statements.