Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem with inheritance in python
    text
    copied!<p>in school we got this class file:</p> <pre><code>class Konto: def __init__(self, nummer): self.__nr = nummer self.__stand = 0 self.__minimum = -1000.0 def getStand(self): return self.__stand def getNr(self): return self.__nr def einzahlen(self, betrag): self.__stand = self.__stand + betrag def auszahlen(self, betrag): if self.__stand - betrag &gt;= self.__minimum: self.__stand = self.__stand - betrag else: print("Auszahlung nicht möglich!") class Sparkonto(Konto): def __init__(self, nummer): Konto.__init__(self, nummer) self.__zinssatz = None self.__minimum = 0 self.__maxAuszahlung = 2000.0 def setZinssatz(self, zinssatz): self.__zinssatz = zinssatz def getZinssatz(self): return self.__zinssatz def auszahlen(self, betrag): if betrag &lt;= self.__maxAuszahlung: Konto.auszahlen(self, betrag) else: print("Auszahlung nicht möglich!") def zinsenGutschreiben(self): zinsen = self.__stand * (self.__zinssatz / 100) self.einzahlen(zinsen) </code></pre> <p>When I run this test programm:</p> <pre><code>#Test from sparkonto import * s = Sparkonto(1) s.einzahlen(1000) print(s.getStand()) s.setZinssatz(4) print(s.getZinssatz()) s.zinsenGutschreiben() print(s.getStand()) s.auszahlen(2500) print(s.getStand()) </code></pre> <p>I get this error</p> <pre><code>1000 4 Traceback (most recent call last): File "/home/malte/home/py3/sparkonto/test.py", line 8, in &lt;module&gt; s.zinsenGutschreiben() File "/home/malte/home/py3/sparkonto/sparkonto.py", line 44, in zinsenGutschreiben AttributeError: 'Sparkonto' object has no attribute '_Sparkonto__einzahlen' &gt;&gt;&gt; </code></pre> <p>We do not know what we are doing wrong. Any guess?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload