Что мне не хватает в моем коде? Я пробовал разные варианты этого кода, может быть, пять. Я запустил код и получил оператор для выполнения, но все еще чего-то не хватает. Имя не печатается вместе с ним. Прикрепил скрин с указанными параметрами.
введите здесь описание изображения
введите здесь описание изображения
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!")
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”))
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!"
Это то, что сработало для меня.
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!'
Это сработало для меня.
Спасибо. Я вижу, чего мне не хватало. '''возврат self.first_name + " " + self.last_name'''. Я несколько раз переписывал код, но всегда пропускал эту часть. Спасибо, еще раз.