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

Lab 5- Colab

Uploaded by

hbashir659
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab 5- Colab

Uploaded by

hbashir659
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

keyboard_arrow_down Lab Task

keyboard_arrow_down Question 1
class account:
def __init__(self,a,b,c):
self.name=a
self.account=b
self.belance=c
def info(self):
print("Account owner is ",self.name)
print("Account number is ",self.account)
print("Your Udhar is ",self.belance)

def withdraw(self):
account=int(input("How much Udhar you want: "))
if account<self.belance:
print("Withdraw Sucessfull")
print(f"Updated Udhar {self.belance+account}")
else:
print("Insufient Balance")

def deposit(self):
y=int(input("How much Udhar you want return: "))
print("Udhar returned Sucessfully")
print(f"Updated Udhar {self.belance-y}")

Ronoa_Zoro = account("Ronoa Zora","458",3000000)


Ronoa_Zoro.info()
print("press 1 for Udhar enter 2 for returning Udhar ")
z=int(input())
if z==1:
Ronoa_Zoro.withdraw()
else:
Ronoa_Zoro.deposit()

Account owner is Ronoa Zora


Account number is 458
Your Udhar is 3000000
press 1 for Udhar enter 2 for returning Udhar
2
How much Udhar you want return: 58710
Udhar returned Sucessfully
Updated Udhar 2941290

keyboard_arrow_down Question #2
class employee:
def __init__(self,a,b):
self.name=a
self.position=b
def info(self):
print("Employee name is ",self.name)
print("Employee position is ",self.position)

class manager(employee):
def __init__(self,a,b,c):
self.name=a
self.team=b
self.team_member=c

def info(self):
print("Manager name is ",self.name)
print("Manager team is ",self.team)
print("Manager team member is ")
self.team_member.info()
class director:
def __init__(self,a,b,c):
self.name=a
self.department=b
self.department_manager=c

def info(self):
print("Director name is ",self.name)
print("Director department is ",self.department)
print("Director department manager is ")
self.department_manager.info()

saif=employee("saif","programmer")
saif.info()
mudassar=manager("mudassar","python",saif)
mudassar.info()
hassan_ejaz=director("hassan ejaz","Mechanical",mudassar)
hassan_ejaz.info()

Employee name is saif


Employee position is programmer
Manager name is mudassar
Manager team is python
Manager team member is
Employee name is saif
Employee position is programmer
Director name is hassan ejaz
Director department is Mechanical
Director department manager is
Manager name is mudassar
Manager team is python
Manager team member is
Employee name is saif
Employee position is programmer

keyboard_arrow_down task 3
class Question:
def __init__(self, text, options, correct_option):
self.text = text
self.options = options
self.correct_option = correct_option

def is_correct(self, player_answer):


return player_answer == self.correct_option

class Player:
def __init__(self, name):
self.name = name

class Quiz:
def __init__(self, questions):
self.questions = questions

def conduct_quiz(self, player):


score = 0
print(f"Welcome {player.name} to the quiz!\n")

for idx, question in enumerate(self.questions, start=1):


print(f"Question {idx}: {question.text}")
for i, option in enumerate(question.options, start=1):
print(f"{i}. {option}")

try:
player_answer = int(input("\nYour answer (enter option number): "))
if player_answer < 1 or player_answer > len(question.options):
print("Invalid option selected. Please try the next question.\n")
continue
except ValueError:
print("Please enter a valid number for the option.\n")
continue

if question.is_correct(player_answer):
print("Correct!\n")
score += 1
else:
print(f"Wrong! The correct answer was {question.correct_option}\n")

print(f"{player.name}, your final score is: {score}/{len(self.questions)}\n")

if __name__ == "__main__":
question1 = Question("What is the capital of Pakitan?", ["Paris", "London", "Islambad", "Rome"], 3)
question2 = Question("who is Ronano Zoro?", ["Navy", "Pirte", "Younko", "nothing"], 2)
question3 = Question("Which planet is known as the Red Planet?", ["Earth", "Mars", "Jupiter", "Saturn"], 2)

questions = [question1, question2, question3]

quiz = Quiz(questions)
player = Player(name="Saif")
quiz.conduct_quiz(player)

Welcome Saif to the quiz!

Question 1: What is the capital of Pakitan?


1. Paris
2. London
3. Islambad
4. Rome

Your answer (enter option number): 1


Wrong! The correct answer was 3

Question 2: who is Ronano Zoro?


1. Navy
2. Pirte
3. Younko
4. nothing

Your answer (enter option number): 2


Correct!

Question 3: Which planet is known as the Red Planet?


1. Earth
2. Mars
3. Jupiter
4. Saturn

Your answer (enter option number): 2


Correct!

Saif, your final score is: 2/3

You might also like