Answer to Question #192542 in Python for Andu

Question #192542

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.


1
Expert's answer
2021-05-12T10:51:03-0400
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) 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS