0% found this document useful (0 votes)
9 views

Python Prac2sanya

The document contains code for two Python programs. The first program defines a Bank_Account class with deposit, withdraw, and display methods to simulate a basic banking interface. The second program defines a numgame class to simulate guessing a random number between 1-20, tracking the number of attempts. Both programs take user input, perform calculations, and display output to the user.

Uploaded by

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

Python Prac2sanya

The document contains code for two Python programs. The first program defines a Bank_Account class with deposit, withdraw, and display methods to simulate a basic banking interface. The second program defines a numgame class to simulate guessing a random number between 1-20, tracking the number of attempts. Both programs take user input, perform calculations, and display output to the user.

Uploaded by

Shivanee Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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