Task 1
Create a class named Ticket that represents the ticket to access a museum. The class has a constructor that takes in input a number representing the base value of the ticket. Moreover, the class has a method named "calcTicketCost(int)". The total cost of the ticket depends on the base ticket value and the number of visitors (normally, number of visitors x base value).
Create a class StudentTicket that inherits from the class Ticket and re-implement the method calcTicketCost(int) by shaping a different logic to the class such as: a discount of 40% is applied to the total ticket price.
class Ticket:
def __init__(self, baseValue):
self.baseValue = baseValue
def calcTicketCost(self, n):
return self.baseValue * n
class StudentTicket(Ticket):
def calcTicketCost(self, n):
discount = 0.4
return self.baseValue * n * (1 - discount)Â
Comments
Leave a comment