0% found this document useful (0 votes)
21 views3 pages

Time Datetime

This document defines a BankAccount class with methods to initialize accounts with a name and deposit, debit and credit amounts, print account statements, and check balances. It also contains code to interactively run transactions on a sample account by prompting the user to select a debit, credit, statement, or balance action.

Uploaded by

Abhishek Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Time Datetime

This document defines a BankAccount class with methods to initialize accounts with a name and deposit, debit and credit amounts, print account statements, and check balances. It also contains code to interactively run transactions on a sample account by prompting the user to select a debit, credit, statement, or balance action.

Uploaded by

Abhishek Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Abhishek singh

12115508
Roll No. 8

from time import time


from datetime import datetime

class BankAccount:
def __init__(self, full_name, initial_deposit):
self.full_name = full_name
self.initial_deposit = initial_deposit
self.account_number = str(int(time() * 1000))
self.balance = initial_deposit
self.transactions = []

def debit(self, amount):


if amount > self.balance:
print("Insufficient funds")
else:
self.balance -= amount
transaction_id = str(int(time() * 1000))
transaction_date = datetime.now().strftime('%Y-%m-%d
%H:%M')
self.transactions.append((transaction_date, transaction_id,
'Debit', amount, self.balance))
print(f"Debited {amount} from account")

def credit(self, amount):


self.balance += amount
transaction_id = str(int(time() * 1000))
transaction_date = datetime.now().strftime('%Y-%m-%d %H:%M')
self.transactions.append((transaction_date, transaction_id,
'Credit', amount, self.balance))
print(f"Credited {amount} to account")

def check_balance(self):
print(f"Available balance: {self.balance}")

def print_statement(self):
print(f"Account Holder Name: {self.full_name}")
print(f"Account Number: {self.account_number}")
print("Transaction Date | Transaction ID | Transaction Type |
Transaction Amount | Available Balance")
for transaction in self.transactions:
print(f"{transaction[0]} | {transaction[1]} |
{transaction[2]} | {transaction[3]} | {transaction[4]}")

if __name__ == '__main__':
full_name = input("Enter your full name: ")
initial_deposit = float(input("Enter initial deposit amount: "))
account = BankAccount(full_name, initial_deposit)
while True:
print("Select transaction type:")
print("1. Debit")
print("2. Credit")
print("3. Print statement")
print("4. Check balance")
choice = int(input())
if choice == 1:
amount = float(input("Enter debit amount: "))
account.debit(amount)
elif choice == 2:
amount = float(input("Enter credit amount: "))
account.credit(amount)
elif choice == 3:
account.print_statement()
elif choice == 4:
account.check_balance()

output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy