My Python Quiz

The ultimate place to learn Python!

Question #31: What numbers get printed

import pickle

class account:
	def __init__(self, id, balance):
		self.id = id
		self.balance = balance
	def deposit(self, amount):
		self.balance += amount
	def withdraw(self, amount):
		self.balance -= amount

myac = account('123', 100)
myac.deposit(800)
myac.withdraw(500)

fd = open( "archive", "w" ) 
pickle.dump( myac, fd)
fd.close()

myac.deposit(200)
print myac.balance

fd = open( "archive", "r" ) 
myac = pickle.load( fd )
fd.close()

print myac.balance