1.

Define a class Train in PYTHON with following description:Data Memberssrc of type stringTnm of type stringdest of type stringcharges of float• A member function Getdata to assign the following values for ChargesDestChargesMumbai1000Chennai2000Kolkata2500Public membersA constructor to initialize the data members.A function InputData() to allow the user to enter the valuesA function displaydata() to display all and call getdata function

Answer»

class train:

def __init__(self):

_src=""

_tnm=""

_dest=""

_charges=0.0

def getdata(self):

if self._dest=="mumbai" or self._dest=="MUMBAI":

self._charges=1000

elif self._dest=="chennai" or self._dest=="CHENNAI":

self._charges=2000

elif self._dest=="kolkata" or self._dest=="KOLKATA":

self._charges=2500

def inputdata(self):

self._src=raw_input("enter the source of journey")

self._tnm=raw_input("enter the train name")

self._dest=raw_input("enter the destination")

def displaydata(self):

print "the source of journey is",self._src

print "the name of the train is",self._tnm

print "the destination of the train is",self._dest

t.getdata()

print "the charges for your journey",self._charges



Discussion

No Comment Found

Related InterviewSolutions