In: Computer Science
***PYTHON PLEASE***
I'd also like to use decimal to two places when calculating the money $$ values for budget and fee areas.
Thank you!
--------------------------------------------------------
Create a Park class. Include the following seven data members:
Name of Park
Location
Type of Park (National, State or Local)
Fee
Number of Employees
Number of visitors reported for the past 12 months
Annual Budget
Write your __init__ class
In addition write four separate instance methods that:
Return a string containing the name of the park, the location and type of park.
Computes the cost per visitor based on annual budget, and the number of visitors during the last 12 months.
Computes the revenue from fees for the past year based on number of visitors and fee.
Prints the values of all of the data members with appropriate labels.
Create a second class to test all aspects of your Park class.
##IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, ELSE COMMENT TO CLEAR DOUBTS
CODE:
class park:
def
__init__(self,name,location,type_,fee,num_emp,num_visitors,annual_budget):
self.name = name
self.location = location
self.type_ = type_
self.fee = fee
self.num_emp = num_emp
self.num_visitors = num_visitors
self.annual_budget = annual_budget
def printNameLocationType(self):
string = "\nNAME ->\t" + self.name + "\nLOCATION ->\t" +
self.location + "\nTYPE ->\t" + self.type_
return string
def getCostPerVisitor(self):
return self.annual_budget/self.num_visitors
def getRevenue(self):
return self.fee * self.num_visitors
def __str__(self):
string = self.printNameLocationType()
string += "\t\nFEE ->\t"+str(self.fee) + "\n\tNUMBER OF VISITORS
->\t" + str(self.num_visitors) + "\n\tCOST PER VISITOR
->\t{:.2f}".format(self.getCostPerVisitor())
string += "\n\tNUMBER OF EMPLOYEE ->\t"+str(self.num_emp) +
"\n\tREVENUE ->\t\t"+str(self.getRevenue()) + "\n\tANNUAL BUDGET
->\t"+str(self.annual_budget)
return string
class driver: #another class to test the park class
def __init__(self):
pass
def run(self):
while(True):
name = input("\nEnter the name of the park: ")
location = input("\nEnter the location of the park: ")
while(True):
type_ = input("\nEnter the type of the park(National, State or
Local): ")
if type_ not in ["National","State","Local"] :
print("Wrong type..... Enter again!")
continue
else:
break
while(True):
try:
fee = int(input("\nEnter the fee: "))
except:
print("Some error occured.....Enter again!")
continue
break
while(True):
try:
num_emp = int(input("\nEnter the number of employees: "))
except:
print("Some error occured.....Enter again!")
continue
break
while(True):
try:
num_visitors = int(input("\nEnter the number of visitors: "))
except:
print("Some error occured.....Enter again!")
continue
break
while(True):
try:
annual_budget = int(input("\nEnter the annual budget: "))
except:
print("Some error occured.....Enter again!")
continue
break
p =
park(name,location,type_,fee,num_emp,num_visitors,annual_budget)
print(p)
print("\nDO YOU WANT TO CONTINUE? (Y FOR YES): ")
if input() not in ['Y','y']:
break
d = driver()
d.run()
CODE PREVIEW: