CodePudding user response:
1. The problem of indentation2. The global and local variables need to know about the knowledge
CodePudding user response:
On the second floor right1, the indentation you have one more tabs
2, your function is can't find the num of the variable, you want inside the function definition num
A simple for loop is
Def func (n) :
Num=0
For I in range (n + 1) :
Num=num + I
Print (num)
Func (100)
CodePudding user response:
Inside the function addGlobal num
CodePudding user response:
def func (n) :
If n==0:
Return 0
The else:
Return the n + func (n - 1)
Print (func (10))
CodePudding user response:
You have to make clear the scope of the function variables, function outside the num of variable and function inside the num is differentCodePudding user response:
Such use variables, is not a good habit