Question: Hello, I'm having some issues with my Python class. I have the following script: class Golf: results=0 def __init__(self,hole,score,par): self.hole = hole self.par = par
Hello,
I'm having some issues with my Python class. I have the following script:
class Golf:
results=0
def __init__(self,hole,score,par):
self.hole = hole
self.par = par
self.result = score
if score > par:
self.results = 'Over Par'
elif score < par:
self.results = 'Under Par'
elif score == par:
self.results = 'At Par'
def displayGolf(self):
print('You scored', self.results, 'on hole #', self.hole,
'with a par of',self.par)
nHole=int(input('Enter the hole number: '))
score=int(input('Enter your score for the hole: '))
#Objects for each hole
hole1=Golf(1,score,3)
hole2=Golf(2,score,4)
hole3=Golf(3,score,5)
if nHole==1:
hole1.displayGolf()
elif nHole==2:
hole2.displayGolf()
elif nHole==3:
hole3.displayGolf()
***************************************************************
However, it seems I have this issue:
The golf scoring program only has the class defined.There should be code in the main body to invoke the class by creating objects that instantiate from the class.
I'm not certain how to fix it, I was wondering if I could get some help from any SME.
Thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
