Error: missing 1 required positional argument

Hello ! I have the following error in the code below:

Traceback (most recent call last):
File “”, line 16, in
TypeError: init() missing 1 required positional argument: ‘sleep’

class Robot:
def init(self, nume, serial_number, hardware, software, sleep):
self.nume = nume
self.serial_number = serial_number
self.hardware = hardware
self.software = software
self.sleep = sleep

def turn_on(self):
    if self.sleep == True:
        return f'{self.nume} is already running'
    else:
        self.sleep == False
        return f'{self.nume} turned on'

r1 = Robot(“John”, ‘12450’, ‘i5’ ‘Python’, True) - line 16
r1.turn_on()
print(r1.turn_on())

r2 = Robot(“Mike”, ‘52048’, ‘i6’ “C++”, False)
r2.turn_on()
print(r2.turn_on())

You forgot the , betrween ‘i5’ and ‘Python’. Also, this line will not work:

    else:
        self.sleep == False

it needs to be this:

elif self.sleep == False:

or just

else:

Hope this helps.

1 Like

Thanks again @Paul ! I needed a fresh pair of eyes! For the else part it worked like I wrote it, I mean I saw it like that in a tutorial, worked with no errors.

1 Like

As for the bit about self.sleep == False , the way the statement is written at the moment (as you showed above) has now effect. You check to see if self.sleep is False but then do not do anything with that information. It is exactly the same as writing

def turn_on(self):
    if self.sleep == True:
        return f'{self.nume} is already running'
    else:
        True
        return f'{self.nume} turned on'

or

def turn_on(self):
    if self.sleep == True:
        return f'{self.nume} is already running'
    else:
        False
        return f'{self.nume} turned on'

That is why I thought is should perhaps be different. The only other option I see for it is if it was meant as a comment and not an actual line of code?

Actually I made a mistake, I wrote it wrong , it was supposed to be like this :beer:

def turn_on(self):
if self.sleep == False:
return f’{self.nume} is already running’
else:
self.sleep ==False
return f’{self.nume} turned on’