You are on page 1of 2

Sanya Sarah Abraham

1022267
Comp B (B3)

Practical 2

Code:
class Bank_Account:
def _init_(self):
self.balance=0
print("Hello, Welcome to deposit deposit and withdrawal machine")
def deposit(self):
amount=float(input("Enter the amount to be deposited: "))
self.balance+=amount
print("\n Amount Deposited:",amount)
def withdraw(self):
amount=float(input("Enter the amount to be withdrawn: "))
if self.balance>=amount:
self.balance-=amount
print("\n The amount withdrawn is ", amount)
else:
print("Insufficent balance!")
def display(self):
print("\n Balance: ",self.balance)
s = Bank_Account()
i=0;
while(i!=1):
s.deposit()
s.withdraw()
s.display()
i=int(input("If you want to continue with banking press 0 else 1 \n"))
Output:

Code:
import random
class numgame:
def __init__(self):
self.number = random.randint(1,20)
self.attempts = 0

def guessnum(self):
self.attempts += 1
guess = int(input("Guess the correct number: "))
if guess == self.number:
print("Congratulations!! you guessed the correct number")
print("You guesssed the number in",self.attempts,"attempts")
elif 1>guess>20:
print("Enter the number btwn 1 to 20")
elif guess < self.number:
print("Too low. Try again")
else:
print("Too high. Try again")
result = numgame.guessnum(self)
print(result)

def run(self):
print("!! Welcome to the number game !!")

game = numgame()
game.run()
game.guessnum()

Output:

You might also like