Beginner seeking help in Python Conditional statements

Hello. I wrote this code but can’t figure out how to create my desired output. It should output on of the following two statements;
“Hello Harry” or “Bye Bob”
Instead however, I cant seem to properly change the “Boy” variable for the correct output.
Please advise, Thank you

Here’s my code:

Since Boy is declared as a global, it can only be seen, but not mutated by a function, unless… It is declared locally as a global.

def ...:
    global Boy

Aside

Naming convention would have us only use capitalization to denote a CLASS, not an ordinary variable.

class Boy:

vs.

boy = 0

Okay, thank you. I think I understand. But then how do i change the variable “boy” into a changeable function in this situation?

boy is just a variable representing an integer value. Once declared as a global inside the function you will be able to mutate it. There is no need to return it since the global will have changed (unless X is 5).

Again, to reiterate, use lowercase variable names unless they represent a class, class Boy: or a global constant, PI = math.pi.

1 Like

One other point. You haven’t attempted to mutate Boy. Boy + 9 doesn’t change the value of Boy. :wink:

:sweat_smile: It doesn’t? And here I thought I only had one issue in the code.

Ah! +=
That made it work! Thank you! Plus global.

1 Like

Thanks guys!!! :heart:

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.