1
나는이 클래스에 시간, 분 및 초 속성이 있으며 set_hour, increment_hour 등과 같은 접근 자 함수 및 변경자 함수도 가지고 있습니다.시간이 정의되지 않았습니다 - 클래스 python
이것은 내 코드입니다. 제대로 작동하지 않습니다. 마지막 줄을 바꿀 때 시간이 정의되지 않았거나 t가 정의되지 않았습니다. 그런데 파이썬 3.2.5.
class Time:
"""The Time class defines the time with
attributes: hour, minute, second
"""
#Attributes
hour = 12
minutes = 00
seconds = 00
#Functions
def get_hour(self):
return self.hour
def get_minute(self):
return self.minute
def get_second(self):
return self.second
def print_time(self):
print("Hello, the current time is", self.hour,":",self.minute,":",self.second)
def set_hour(self, new_hour):
self.hour = new_hour
t.set_hour("1")
print(t.get_hour())
print(t.print_time())
t = Time()
't = Time()'을 먼저 넣고 그 줄을 들여 쓰기를 시도하십시오. –
코드에서 문서 상단에'class Time :'이 있는데 맨 아래에 들여 쓰지 않은 코드가 있습니까? –
하단의 라인을 uninedenting하고 고쳐, 고마워요! – Coder77