<p><code>cashier</code>的各种函数不返回任何内容,因此打印只是打印函数的字符串表示形式。您可以让函数返回如下字符串:</p>
<pre class="lang-py prettyprint-override"><code>class Cashier: # PEP8 calls for CamelCase here
def deposit(self):
pin = input("Please type pin to proceed")
if Account.pin == pin:
return "who would you like to send money to?"
else:
return "Invalid pin"
def transfer(self):
pass
def withdraw(self):
withdrawal = input("How much money do you want to withdraw? (there is a limit up to 10,000$ a day!)")
Account.balance -= int(withdrawal)
if int(withdrawal) > 10000:
return "withdrawals cannot be larger than 10,000 a day!"
elif int(withdrawal) > Account.balance:
return "your Account does not have enough funds to complete your transaction"
else:
return "Transaction successful!\nPlease collect your money"
</code></pre>
<p><strong>编辑:</strong>我删除了初始值设定项,因为它们什么都没做。您需要用<code>cashier = Cashier()</code>实例化出纳,然后用<code>cashier.withdraw()</code>调用<code>Cashier</code>函数</p>
<p>这里对类的工作方式(以及OOP的一般工作方式)有一个基本的误解。在继续之前,你应该通读一遍<a href="https://docs.python.org/3/tutorial/classes.html" rel="nofollow noreferrer">Python docs on building classes</a></p>