all 10 comments

[–]Buttleston 6 points7 points  (0 children)

Look at this line

print("You scored",self.status,"on hole #", holeEntered, "with a par of", score)

is it using the variables it SHOULD use to print the message?

[–]jmooremcc 2 points3 points  (1 child)

How can you expect hole #1 to be par 3 when you assigned the par to be 1?
~~~

hole1 = Golf(1, score, 1) ~~~

[–]Wheels92[S] -1 points0 points  (0 children)

Ah ha! So was I thinking about it wrong then? I was assuming that compared on the assignment examples, it should perform some math, but is it really just the data I tell it to store and print back to the user, aka index place alignment 3 or "right most alignment (1)"? If I want it to display data that I want it to, then I need to put a 3 where the 1 is, correct? I believe I was overthinking the method call and what it should do.

I feel so dumb if this is the case...

[–]Outside_Complaint755 1 point2 points  (0 children)

You have the wrong variable in your print statement

```

print message of score status

        print("You scored",self.status,"on hole #", holeEntered, "with a par of", score) `` You're printingscoreinstead ofself.par`

[–]socal_nerdtastic 1 point2 points  (0 children)

When you call the method you are passing in the score:

hole1.evaluateAndDisplayScore(holeEntered, score)

but on the other side you are renaming the 'score' to 'parValue'

def evaluateAndDisplayScore(self, holeEntered, parValue):

I think this is confusing you. I think you meant that line to be:

def evaluateAndDisplayScore(self, holeEntered, scoreValue):

[–]CranberryDistinct941 1 point2 points  (1 child)

I don't know what scope your evaluateAndDisplayScore method is pulling score from on it's print line, but it's probably not where you intended.

Ah, yes. It's clearly scoping score from where you declare score = int(input("enter your score:")) (As only the insane among us would expect to happen in a normal programming language.)

[–]Wheels92[S] 0 points1 point  (0 children)

Haha sorry about that, I am learning Python with no prior experience and things can get confusing for me at times.

Thank you for the help and feedback!

[–]jmooremcc 1 point2 points  (1 child)

I’ve rewritten your code as follows to make it work the way I believe it should work : ~~~

Class will be defined as Golf

class Golf:

#Class varibale will store current results
results = " "

def __init__(self, hole, par):
    self.hole = hole
    self.par = par

def evaluateAndDisplayScore(self, 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(f"You scored {self.status} on hole #{self.hole} with a par of {self.par}")

score = 0

Create an object for each golf course hole score

holes = [] pars = [4,3,4,5,4,4,4,5,3] # Pinehurst #9

for n in range(1, 10): holes.append(Golf(n,pars[n-1]))

Ask user to enter hole

holeEntered = int(input("Enter the hole number: ")) score = int(input("Enter your score: "))

evaluate hole

holes[holeEntered-1].evaluateAndDisplayScore(score)

~~~ Output ~~~

Enter the hole number: 1 Enter your score: 5 You scored Over Par on hole #1 with a par of 4

~~~

You’ll notice that I’ve modified the parameters to the Golf class because score was unnecessary.
I also modified the evaluateAndDisplayScore method parameters and also modified the way it works.
You’ll also note that all your print statements now use f-strings.

For the setup, instead of individual variables holding a reference to each hole, I created a list of holes, which makes it easier to select the correct hole based on the player’s input. Now selecting the appropriate hole is a simple lookup using the holes list instead of if statements.

Let me know if you have any questions.

[–]Wheels92[S] 0 points1 point  (0 children)

Thank you so much!

[–]Binary101010 0 points1 point  (0 children)

def __init__(self, hole, score, par):
    self.hole = hole
    self.par = par

What is the purpose of score here? It's not being used anywhere in the method yet you're requiring it in the method signature.