Hi there!
I am a beginner in python so I like to experiment. I was trying object oriented programming when I got stuck on this problem.
Here is my code.
The problem is in the last line of code. How can I access a nested inner function using object of a class?
It is for general practise only.
class Train:
def __init__(self,name,fare,seats):
self.name=name
self.fare=fare
self.seats=seats
def getStatus(self):
print(f"The name of the train is {self.name}")
print(f"The number of seats in the train is {self.seats}")
def fareInfo(self):
print(f"The fare of the train is {self.fare}")
def bookTicket(self):
if(self.seats>0):
print("your ticket has been booked! Your seat number is {self.seat}")
self.seats=self.seats-1
else:
print("Sorry! This train is full!")
def seatslist(self):
seatno=[]
for i in range(1,self.seats+1):
seatno.Train.append(i)
print(seatno,end="")
def cancelticket(self,n):
for n in seatno:
seatno.remove(n)
print(f"The following ticket numbers are available:{seatno} ")
Intercity= Train("Intercity :14015",90,10)
Intercity.getStatus()
Intercity.fareInfo()
Intercity.seatslist()
Intercity. cancelticket(7) #here I want to use the nested function