I apologize if this is a dumb or repeating question firstly. I have been learning python for about 2 weeks now and I keep having small problems with loops. For example.
def factorial(n):
if n < 2: # I understand once the number becomes < than 2 the loop continues
return 1. #and here we return the value 1
result = n * factorial(n-1) #why do we subtract 1 from n?
return result
factorial(5) #my random number
I am having trouble understanding why you subtract 1 from n. Shouldn't you add 1 instead to include the number?
In my mind it looks like this: result = n(1) * factorial((1)-1) # doesn't n stay = to 1 or am i mistaken?
Thank you for you help. Sorry again if its an idiot question.