How this code works? | Sololearn: Learn to code for FREE!


How this code works?

If I input 0 to this fact function . The answer is 1. But why the for loop is not working for this ? Explain.

3 Answers

New Answer


When n is 0, it will be range(1, 1). The start and the end is the same and thus the loop doesn't run.


I don't understand your question. You don't need the 'if' statement, just a single 'fact = 1', i.e. delete lines 2 and 3. The for loop is working. In the case of n = 0, it runs from 1 to 1.