Python Object-Oriented Python Advanced Objects Double

Trying to get it to recognize Double

Syntax error???

doubler.py
class Double(int):
    def__new__(int)
    self = int.__new__(self)
    return self

2 Answers

Steven Parker
Steven Parker
207,980 Points

There's a few issues:

  • there should be a space after the keyword "def"
  • the instructions say that the "method should accept self and one argument"
  • the method code lines need to be indented more than the "def" line
  • the instructions say to "Convert the argument to an int and return it."

I will try again

After some serious "rubber ducking," here's what passed that challenge: def new(self, int): return int * 2 After some experimentation I found that int * 2 passed the third echelon of this code challenge! Seriously, thank you :)

Steven Parker
Steven Parker
207,980 Points

Congratulations! But in future you might also want to avoid using a special keyword (like "int") as a variable name.

Yes, I don't understand why they insisted on using a special keyword like "int." I would have rather used something else more appropriate like maybe "init." Or anything along those lines

Steven Parker
Steven Parker
207,980 Points

The "int" specified with the class is necessary, and is the keyword. But the terms on the "def" line are parameter names that you choose. Avoiding keywords or common function names can prevent errors that can be hard to track down.