I am a very begginner in python programming. I am making a Railway registration form in python and want some features - book a ticket and cancel a ticket. I have made the function for booking ticket(s). But I can't make a function for canceling ticket(s). An example, if 10 people booked 10 seats, and 8th people cancelled his seat, the seats will be like this - 1, 2, 3, 4, 5, 6, 7, 9, 10. Please help me !
class Train:
def __init__(self, name, fare, seats):
self.name = name
self.fare = fare
self.seats = seats
def getStatus(self):
print(f"Name of the train is {self.name}")
print(f"Available seats: {self.seats}")
def fareInfo(self):
print(f"Price of ticket is: Rs. {self.fare}")
def bookTicket(self):
if (self.seats>0):
self.seats = self.seats - 1
print(f"Your ticket has booked sucessfully! {self.seats} seats are left")
else:
print("No seats are available!")
def cancelTicket(self, seatNo):
pass
intercity = Train("194673: Dhabalgiri Express", 843, 2)
intercity.getStatus()
intercity.fareInfo()
intercity.bookTicket()
intercity.bookTicket()
intercity.bookTicket()