Swaraj Pandey 21162121036 Bda Sem 4 - 44
Swaraj Pandey 21162121036 Bda Sem 4 - 44
21162121036
BDA SEM 4 - 44
Practical 8
CODE:-
def bankoptions():
print("Enter 1 To add new Customers.")
print("Enter 2 To check your account details. ")
print("Enter 3 To Deposit your money")
print("ENTER 4 To withdraw your money")
print("ENTER 5 To exit.")
class bank:
def AddDetails(self):
n=input("Enter your name:- ")
name.append(n)
acc=int(input("Enter your Account number: "))
account_number.append(acc)
balance.append(1000)
ac_type=int(input("Enter 1 to create Saving account // Enter 2 to create
Current account: "))
if ac_type==1:
type.append("Saving")
else:
type.append("Current")
def ShowDetails(self):
n=input("Enter your name:- ")
length=len(name)
if n in name:
acc=int(input("Enter Your Account number:- "))
if acc in account_number:
for i in range(0,length):
if n==name[i] and acc==account_number[i]:
print("name: ",name[i])
print("Account Number: ",account_number)
print("Account Balance: ",balance[i])
print("Account Type: ", type[i])
def setbalance(self):
n=input("Enter your Name: ")
length=len(name)
if n in name:
acc=int(input("Enter your acc number: "))
if acc in account_number:
SWARAJ PANDEY
21162121036
BDA SEM 4 - 44
for i in range(0,length):
if n==name[i] and acc==account_number[i]:
bal=int(input("Enter your deposite value: "))
balance[i]=balance[i]+bal
print("Updated Balance: ",balance[i])
def getbalance(self):
n=input("Enter your name: ")
length=len(name)
if n in name:
acc=int(input("Enter your Account Number: "))
bal=int(input("Enter Amount: "))
if acc in account_number:
for i in range(0,length):
if n==name[i] and acc==account_number[i]:
bankbbalance=balance[i]-bal
if(bankbbalance<=1000):
print("Insufficient Balance ")
else:
balance[i]=balance[i]-bal
print("Updated Balance: ",balance[i])
name=[]
account_number=[]
balance=[]
type=[]
ob=bank()
temp=1
while(temp!=0):
bankoptions()
opt=int(input("Enter your choice: "))
if opt==1:
ob.AddDetails()
elif opt==2:
ob.ShowDetails()
elif opt==3:
ob.setbalance()
elif opt==4:
ob.getbalance()
elif opt==5:
temp=0
else:
print("Invalid Input")
SWARAJ PANDEY
21162121036
BDA SEM 4 - 44
2. Design a class named StopWatch. The class contains:
The private data fields startTime and endTime with get methods.
A constructor that initializes startTime with the current time.
A method named start() that resets the startTime to the current time.
A method named stop() that sets the endTime to the current time.
A method named getElapsedTime() that returns the elapsed time for the stop watch in
milliseconds.
Write a test program that measures the execution time of adding numbers from 1 to
1,000,000.
CODE:-
import time as t
import random as rand
class StopWatch():
def __init__(self):
self.startTime=t.time()
def startTime(self):
return self.startTime()
def endTime(self):
return self.endTime()
def start(self):
self.startTime=t.time()
def stop(self):
self.endTime=t.time()
def getElapsedTime(self):
return int(1000*(self.endTime - self.startTime))
SWARAJ PANDEY
21162121036
BDA SEM 4 - 44
def main():
s=1000000
stopwatch=StopWatch()
sum=0
for i in range(1,s+1):
sum+=i
stopwatch.stop()
print("Execution Time",stopwatch.getElapsedTime(),"ms")
main()
OUTPUT:-
SWARAJ PANDEY
21162121036
BDA SEM 4 - 44
3. A small module for manipulation of complex numbers is being developed for ease of
research related work. Implement add() for addition, mul() for multiplication , sub() for
subtraction of two complex numbers. By default, a complex number will be assigned an
imaginary value of 3. Also ensure that mul() cannot be ever 0 ; so program should raise
an error.
CODE:-
class Complex:
def initComplex(self):
self.realPart = int(input("Enter the Real Part: "))
self.imgPart = int(input("Enter the Imaginary Part: "))
def display(self):
print(self.realPart,"+",self.imgPart,"i", sep="")
def sum(self, c1, c2):
self.realPart = c1.realPart + c2.realPart
self.imgPart = c1.imgPart + c2.imgPart
def mul(self,c1,c2):
SWARAJ PANDEY
21162121036
BDA SEM 4 - 44
self.realPart = (c1.realPart * c2.realPart) - (c1.imgPart * c2.imgPart )
self.imgPart = (c1.realPart * c2.imgPart) + (c1.imgPart * c2.realPart)
def display_mul(self):
if self.realPart != 0:
print("Multiplication of two complex numbers is ",end="")
print(self.realPart,"+",self.imgPart,"i", sep="")
else:
print("Error Multiplication of two complex numbers must not be zero.")
def sub(self,c1,c2):
self.realPart = c1.realPart - c2.realPart
self.imgPart = c1.imgPart - c2.imgPart
c1 = Complex()
c2 = Complex()
c3 = Complex()
c4 = Complex()
c5 = Complex()
print("Enter first complex number")
c1.initComplex()
print("First Complex Number: ", end="")
c1.display()
print("Enter second complex number")
c2.initComplex()
print("Second Complex Number: ", end="")
c2.display()
print("Sum of two complex numbers is ", end="")
c3.sum(c1,c2)
c3.display()
c4.mul(c1,c2)
c4.display_mul()
print("Subtraction of two complex numbers is ",end="")
c5.sub(c1,c2)
c5.display()
OUTPUT:-