Last answered:

06 Nov 2021

Posted on:

10 Apr 2021

2

Use of Global count instead of local count variable

Hi, I don't 100% understand why this function only works when the 'Global' keyword is used with the count variable.

Why doesn't this function work if we just declare 'count' within the function, instead of outside it? I assume it's something to do with recursion, but I'm not sure.

My solution was different from the instructor's, so I didn't need to use this global keyword.

Thanks for your help.

1 answers ( 0 marked as helpful)
Posted on:

06 Nov 2021

1

if we use only count like a normal variable every time we use the recursion function, we put count = 0 but with the global variable we only call count = 0 for the first time and then only call the variable count into the function.

Submit an answer