Thanks for the clarification on that ichabod. It is very helpful with reading code understanding the syntax and style.
If you failed to define user and comp in game() by calling the values ala
From what I understand, it's standard convention to define your primary function as main(). Doesn't mean you have to, but reviewers will understand that is the function that is the main purpose of your program. If you do decide to implement separate functions, it's something you'll want to remember.
I hope someone other than me learned something from this reply.
Quote:I get an error if I set the user and comp outside the game function.
def fn1(): user,comp = 1,2 print(j) return x,y,z def fn2(): j = 'outside function' return j fn2() fn1() print(user,comp)If you run this, you will get an error that "j" isn't defined. Even though in fn2() it is. The reason is because variables are only defined in the function. The variable "j" in fn2() is a different variable than the "j" in fn1().
return j
means that the value is available to be called in global or different functions. Once you define j in fn1(), the same thing will happen with user and comp since I never defined them at global and never defined them by calling their values from fn1().If you failed to define user and comp in game() by calling the values ala
user, comp = function_where_you_defined()
or game(user,comp)
, you will get a trace back error.Quote:I tried returning comp and user after adding 1 in my if and elif statements but that just broke the loopCopied from the Python Doc 7.6. The return statement: "return leaves the current function call with the expression list (or None) as return value... In a generator function, the return statement indicates that the generator is done and will cause StopIteration to be raised."
From what I understand, it's standard convention to define your primary function as main(). Doesn't mean you have to, but reviewers will understand that is the function that is the main purpose of your program. If you do decide to implement separate functions, it's something you'll want to remember.
I hope someone other than me learned something from this reply.