Created
May 2, 2023 16:19
-
-
Save TanjimReza/9e21bae199885270f7287bc2c9ed6c22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#task 18 | |
class User: | |
def __init__(self,name,destination,typ="Single"): | |
self.name=name | |
self.destination=destination | |
self.typ=typ | |
def status(self): | |
print(f'Status: {self.name} is looking for a shared ride!') | |
class Uber: | |
def __init__(self,cn,typ,*args): | |
self.cn=cn | |
self.tp=typ | |
self.args=args | |
def details(self): | |
a='' | |
for i in self.args: | |
a=a+' --> '+i | |
a=a[4:] | |
print(f'Car number: {self.cn}\nType: {self.tp}\nRoutes: {a}') | |
def pick(self,*obj): | |
for i in obj: | |
if i.typ!=self.tp: | |
print(f'{i.name} is looking for a different ride.') | |
elif i.destination in self.args and i.typ==self.tp: | |
print(f'{i.name} has been picked up.') | |
elif i.destination not in self.args: | |
print(f"{i.name}'s destination is different from this car's route.") | |
user1 = User("Brooks", "Banani", "Shared") | |
user2 = User("Jocelyn", "Uttara") | |
user3 = User("Robert", "Gulshan", "Shared") | |
user4 = User("Langdon", "Mohakhali", "Shared") | |
user1.status() | |
user2.status() | |
user3.status() | |
user4.status() | |
print("----------------------------------") | |
car1 = Uber("0K32BH", "Shared", "Mohakhali", "Banani", "Nikunja", "Uttara") | |
car1.details() | |
print("----------------------------------") | |
car1.pick(user1,user2,user3,user4) | |
print("----------------------------------") | |
user1.status() | |
user2.status() | |
user3.status() | |
user4.status() | |
print("----------------------------------") | |
car2 = Uber("5GD2BD", "Single", "Uttara") | |
car3 = Uber("4T12FR", "Shared", "Gulshan", "Bashundhara") | |
car2.details() | |
car3.details() | |
print("----------------------------------") | |
car2.pick(user2, user3) | |
print("----------------------------------") | |
car3.pick(user3) | |
print("----------------------------------") | |
user2.status() | |
user3.status() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment