STATIC COUNTER LEVEL-2| SET 3| Infosys Springboard|OOP using Python| Naan mudhalvan

preview_player
Показать описание
#naanmudhalvan #infosys #springboard
#answers
#objectorientedprogrammingusingpython
#answersdotcom

Write a Python program to generate tickets for online bus booking, based on the class diagram given below.



Method description:

Initialize static variable counter to 0
validate_source_destination(): Validate source and destination. source must always be Delhi and destination can be either Mumbai, Chennai, Pune or Kolkata. If both are valid, return true. Else return false
generate_ticket():
Validate source and destination
If valid, generate ticket id and assign it to attribute, ticket_id. Ticket id should be generated with the first letter of source followed by first letter of destination and an auto-generated value starting from 01 (Ex: DM01, DP02,.. ,DK10,DC11)
Else, set ticket_id as None
Note: Perform case insensitive string comparison

For testing:

Create objects of Ticket class
Invoke generate_ticket() method on Ticket object
Display ticket id, passenger name, source, destination
In case of error/invalid data, display appropriate error message
Рекомендации по теме
Комментарии
Автор

#OOPR-Exer-7
#Start writing your code here
class Ticket:
counter=0
def __init__(self, passenger_name, source, destination):

self.__source=source.lower()

self.__ticket_id=None

def get_passenger_name(self):
return self.__passenger_name
def get_source(self):
return self.__source
def get_destination(self):
return self.__destination
def get_ticket_id(self):
return self.__ticket_id
def
if self.__source=="delhi":
if self.__destination=="mumbai" or self.__destination=="kolkata" or self.__destination=="chennai" or self.__destination=="pune":
return True
else:
return False
else:
return False
def generate_ticket(self):
if
Ticket.counter+=1
if Ticket.counter<10:

else:

return self.__ticket_id.upper()
else:
self.__ticket_id=None

T1=Ticket("mohan", "delhi", "mumbai")
T2=Ticket("Ram", "Delhi", "Pune")
print(T1.generate_ticket())
print(T2.generate_ticket())

answersdotcom-bglx
Автор

Upload Assignment on Dependency and List Objects - level 2

gowtham
Автор

Upload Assignment on Dependency and List Objects - level 2

Elango-lm
Автор

Upload Assignment on Dependency and List Objects - level 2

comali
welcome to shbcf.ru