TwilioQuest -помощь с моим кодом. Класс Python с именем Citizen

#python

#python

Вопрос:

Чего мне не хватает в моем коде? Я пробовал разные варианты этого кода, может быть, пять. Я запустил код и получил инструкцию для выполнения, но все еще чего-то не хватает. Имя не печатается вместе с ним. Прилагается скриншот с заданными параметрами.

введите описание изображения здесь

введите описание изображения здесь

 class Citizen:
  """
  this class is to describe a citizen of the City of Python
  """   
def __init__(self, first_name, last_name): 
    self.first_name = Rey
    self.last_name = Rizo
def full_name(x):
    x = self.first_name   self.last_name
def greeting(greet):
    full_name = raw_input(full_name)
    return greet   x
print("For the glory of Python!")
 

Ответ №1:

 class Citizen:
    "this class is to describe a citizen of the City of Python"   
    def __init__(self, first_name, last_name): 
        self.first_name = first_name #this is an instance variable
        self.last_name = last_name
    def full_name(self):    #This is an instance method
        return self.first_name   " "   self.last_name  #This took the 2 instance variables and put them together
    greeting = "For the glory of Python!"
 

Это то, что сработало для меня.

Комментарии:

1. Спасибо. Я вижу, чего мне не хватало. «‘возвращает self.first_name » » self.last_name»‘. Я несколько раз переписывал код, но всегда пропускал эту часть. Еще раз спасибо.

Ответ №2:

 class Citizen:
    """a citizen of the City of Python"""

    def __init__(self, first_name, last_name):
        self.first_name = first_name
        self.last_name = last_name


    def full_name(self):
        return (f'{self.first_name} {self.last_name}')

    greeting = 'For the glory of Python!'
 

Это сработало для меня.

Ответ №3:

 class Citizen:
    """
    this class is to describe a citizen of the City of Python
    """   
    def __init__(self, first_name, last_name): 
        self.first_name = first_name
        self.last_name = last_name
    def full_name():
        return self.first_name   self.last_name

    def greeting(greet):
        return greet   self.full_name()
 

При инициализации нового гражданина используйте:

 citizen = Citizen(“first_name”, “last_name”)
 

Чтобы напечатать имя:

 print(citizen.full_name)
 

Чтобы приветствовать:

 print(citizen.greeting(“Hello”))