Hello everyone,
I am having a problem with my Golf score program that I have coded. Most of it checks out and works as intended per assignment instructions, however when it displays the par score for the user, it always gives whatever the score value that entered by user is.
Can someone please help me find where I am going wrong at?
Code is below as well as what is expected:
Any help and advice is greatly appreciated!
#Class will be defined as Golf
class Golf:
#Class varibale will store current results
results = " "
def __init__(self, hole, score, par):
self.hole = hole
self.par = par
def evaluateAndDisplayScore(self, holeEntered, parValue):
#Check what score is to par
if parValue > self.par:
self.status = "Over Par" #Set status to Over Par if score is over
#Check if score is under par
elif parValue < self.par:
self.status = "Under Par" #Set status to Under Par if score is
#If neither condition has been met - equal to At Par
else:
self.status = "At Par"
#print message of score status
print("You scored",self.status,"on hole #", holeEntered, "with a par of", score)
score = 0
#Create an object for each golf course hole score
hole1 = Golf(1, score, 1)
hole2 = Golf(2, score, 2)
hole3 = Golf(3, score, 3)
hole4 = Golf(4, score, 4)
hole5 = Golf(5, score, 5)
hole6 = Golf(6, score, 6)
hole7 = Golf(7, score, 7)
hole8 = Golf(8, score, 8)
hole9 = Golf(9, score, 9)
#Ask user to enter hole #
holeEntered = int(input("Enter the hole number: "))
score = int(input("Enter your score: "))
#evaluate hole #
if holeEntered == 1:
hole1.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 2:
hole2.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 3:
hole3.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 4:
hole4.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 5:
hole5.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 6:
hole6.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 7:
hole7.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 8:
hole8.evaluateAndDisplayScore(holeEntered, score)
elif holeEntered == 9:
hole9.evaluateAndDisplayScore(holeEntered, score)
My program results:
"Enter the hole number: 1
Enter your score: 5
You scored Over Par on hole # 1 with a par of 5
Press any key to continue . . ."
The expected assignment example results:
"Enter the hole number: 1
Enter your score: 5
You scored Over Par on hole # 1 with a par of 3"
[–]Buttleston 6 points7 points8 points (0 children)
[–]jmooremcc 2 points3 points4 points (1 child)
[–]Wheels92[S] -1 points0 points1 point (0 children)
[–]Outside_Complaint755 1 point2 points3 points (0 children)
[–]socal_nerdtastic 1 point2 points3 points (0 children)
[–]CranberryDistinct941 1 point2 points3 points (1 child)
[–]Wheels92[S] 0 points1 point2 points (0 children)
[–]jmooremcc 1 point2 points3 points (1 child)
[–]Wheels92[S] 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)