-1
프로그램의 아이디어는"언어 "를 취해 숫자로 변환하는 것입니다. 10 P (20) T = 40 V = 10보다 작은 80 아무것도 정상 수치로 표시됩니다 언어는 아주 쉽게 구축이다" 'int'객체에 'getal'속성이 없습니다. Pythton
K는 = =
이제 숫자는 안 걱정할 필요가있는 부분이 있으니 여기서 설명하기 쉽습니다. 내가
말하는 오류를 얻을 doctest가""" >>>612 // Mangarevaans(26) Mangarevaans('P3') """
을 실행할 때 이제
def mag2arab(getal): #this function is designed to turn the letters into the normal numbers we're used to mag = str(getal) waarde = {"K": 10, "P": 20, "T": 40, "V": 80} arab = 0 for index, j in enumerate(mag): if index == 0 and j.isnumeric(): if len(getal) == 1: x = 0 else: x = 1 arab += int(j) * waarde[mag[x]] elif j.isnumeric(): arab += int(j) elif not (str(mag[0]).isnumeric() and index == 1): arab += waarde[j] return arab class Mangarevaans(): """ >>>612 // Mangarevaans(26) Mangarevaans('P3') """ def __init__(self, getal): if isinstance(getal, int): assert 1 <= getal < 799, 'ongeldige waarde' #this is one of the rules of the language that if there is a number it should be between these values self.getal = getal else: for letter in getal: if isinstance(getal, str): for letter in getal: if letter in "VTPK": self.getal = getal else: raise AssertionError('ongeldige waarde') self.getal = mag2arab(getal) def __int__(self): return self.getal def __str__(self): return arab2mag(self.getal) def __repr__(self): return f"Mangarevaans('{str(arab2mag(self.getal))}')" def __rfloordiv__(other, self): return Mangarevaans(other // self.getal) #The problem occurs here
을 :
나는 다음과 같은 보인다 "Mangarevaans"라는 클래스를 구축
'int'객체에 'getal'속성이 없습니다.
하지만 문자열로 내 자신을 변경하는 경우 I는 속성 "getal"는 "STR에 속하는 경우
'str을'객체가 내가 정의 할 수있는 방법을 더 속성 'getal'
이 없습니다 얻을 "또는"int "?
아무도 도와 줄 수 있습니까?
고마워요 이미
: 대신
합니다. 고마워요. –
그게 도움이 됐어요. BTW, 당신은 [upvote] (http://stackoverflow.com/help/privileges/vote-up)에 대한 특권이 있습니다. ;) –
나는 충분히 "경험"이 없었기 때문에 전에는 효과가 없었습니다. D –