P
P
phawer-72020-08-14 10:26:41
Python
phawer-7, 2020-08-14 10:26:41

Simple Python code but giving an error?

class Robot:
  population = 0

  def __init__(self, name):
    self.name = name
    print("Инициализация {0}".format(self.name))
    
    Robot.population += 1
  
  def __del__(self):
    print("{0} уничтожается!".format(self.name))

    Robot.population -= 1

    if Robot.population == 0:
      print('{0} был последним...'.format(self.name))
    else:
      print('{0:d} работающих роботов'.format(\Robot.population))

  def sayHi(self):
    print('Приветсвую! Меня называют {0}'.format(self.name))

  def howMany():
    print(' У нас {0:d} роботов'.format(Robot.population))

  howMany = staticmethod(howMany)

droid1 = Robot('R2-D2')
droid1.sayHi()
Robot.howMany()

droid2 = Robot('C-3PO')
droid2.sayHi()
Robot.howMany()

print("Роботов уничтожим)))))))))))))))))))))))))))0)0000)000")

del droid1
del droid2

Robot.howMany()


I'm reading the book "Python Bite".
I did the same as in the king, but it gives an error.
HELP

Error:
SyntaxError: unexpected character after line continuation character

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-08-14
@phawer-7

.format(\Robot.population))
This backslash is what?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question