Click on account.py to get source.
class account(object):
"""
Markus Hitz's first C++ example in Python
"""
def __init__(this, start=0):
this.balance = start
def deposit(this, amount):
this.balance += amount
def withdraw(this, amount):
if this.balance >= amount:
this.balance -= amount
else:
print("You are broke\n")
amount = this.balance
this.balance = 0.0
return amount
def getBalance(this):
return this.balance
acc1 = account()
print("Default balance", acc1.getBalance())
acc1.deposit(1000)
print("New balance", acc1.getBalance())
acc2 = account(5000.0)
print("Second constructor", acc1.getBalance())
w = acc2.withdraw(10000.0)
print("w =",w,", new balance acc2", acc2.getBalance())