#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목기말 기출 코드좀 봐주실 수 있나요2020-06-16 16:28
작성자

 기말고사 문제를 풀었는데 __init__과 __eq__에서 syntax error가 발생하네요.. 아래의 링크는 발생한 오류들의 목록이고... 그 외의 함수 피드백좀 부탁드립니다.

http://colorscripter.com/s/akxSCbW 

def get_integer(input):
if (type(input) == int):
return input
elif (type(input) == float):
return int(input)
elif (type(input) == str):
try:
return int(input)
except:
return 0
elif (isinstance(input, MyInteger)):
return input
else:
return 0

class MyInteger:
current_value = []
press = 0
def __init__(self, input):
self.current_value.append(get_integer(input))
def __eq__(self, other):
get_integer(other)
return self.current_value[-1] == other
def pressAdd(self, input):
new_current = self.current_value[-1] + get_integer(input)
self.current_value.append(new_current)
self.press += 1
return self.current_value[-1]

def PressSub(self, input):
new_current = self.current_value[-1] - get_integer(input)
self.current_value.append(new_current)
self.press += 1
return self.current_value[-1]

def getCurrentVariable(self, mode):
if mode == None:
return self.current_value[-1]
elif mode == "hex":
hex_current_value = '0x' + hex(self.current_value[-1])
return hex_current_value
elif mode =="oct":
oct_current_value = '0o' + oct(self.current_value[-1])
return oct_current_value
elif mode =="bin":
bin_current_value = '0b' + bin(self.current_value[-1])
return bin_current_value
else:
return self.current_value

def resetCurrentVariable(self):
self.current_value.clear()
self.current_value.append(0)
return self.current_value

def rollbackCurrentVariable(self):
if self.press < 1:
self.current_value[-1] = 0
else:
self.current_value.pop()
self.press -= 1
return self.current_value[-1]
댓글