8. import sqlite3.

Added on - 22 Sep 2019

  • 15

    pages

  • 994

    words

  • 135

    views

  • 0

    downloads

Showing pages 1 to 4 of 15 pages
1import sqlite3class Account:"""serialno,holder,address"""def __init__(self,serialno,holder,address):self.serialno=serialnoself.holder=holderself.address=addressdef insertDB(self):conn=sqlite3.connect('accountsinfo.db')cur=conn.cursor()cur.execute('INSERT INTO
2Account(SerialNo,AccountHolder,Address)values(?,?,?)',(self.serialno,self.holder,self.address))conn.commit()def deposit(self,amount):conn=sqlite3.connect('accountsinfo.db')cur=conn.cursor()cur.execute('INSERT INTO Deposits(SerialNo,Amount)values(?,?)',(self.serialno,amount))conn.commit()cur.close()def withdraw(self,amount):conn=sqlite3.connect('accountsinfo.db')
3balance=0.0cur=conn.cursor()cursor=cur.execute("SELECT sum(Amount) from Depositswhere SerialNo=?",(self.serialno,))row = cur.fetchone()if row == None:passelse:balance=float(row[0])cur1=conn.cursor()cur1.execute("SELECT sum(Amount) from Withdrawal whereSerialNo=?",(self.serialno,))try:for row1 in cur1:
4balance=balance-float(row1[0])except:passif amount>balance:print('Not enough balance')returncur=conn.cursor()cur.execute('INSERT INTO Withdrawal(SerialNo,Amount)values(?,?)',(self.serialno,amount))conn.commit()cur.close()def __str__(self):conn=sqlite3.connect('accountsinfo.db')
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document