2017-08-31 93 views
-1

我正在學習Python,但我找不到這樣的答案:如何在這種情況下實現add方法? (Python)

「實現add方法,它應該爲當前字段添加數量」。

class Complex: 
    def create(self, real_part, imag_part): 
     self.r = real_part 
     self.i = imag_part 

class Calculator: 
    current = 0 

    def add(self, amount): 
     *i need to edit only this line* 

    def get_current(self): 
     return self.current 
+0

這是Pycharm埃杜教程(Python簡介任務43 50) 感謝分享我們的一個問題。 –

回答

0

你可以這樣做:

def add(self, amount): 
    self.current += amount 
+0

謝謝,這工作,我現在瞭解內容。謝謝! –

+0

歡迎您:) :) –

+0

@JackHavear歡迎來到堆棧溢出傑克,請記住如果回答您的問題「接受」答案。點擊答案旁邊的灰色勾號。 –

相關問題