Skip to content

This code demonstrates a common error in recursive functions: forgetting to handle negative input. The factorial function is only defined for non-negative integers. Calling it with a negative number leads to infinite recursion and a RecursionError.

Notifications You must be signed in to change notification settings

Bug-Hunter-X/Python-RecursionError-in-Factorial-Function-o0oop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Python RecursionError Example

This repository demonstrates a common error in recursive functions in Python: forgetting to handle edge cases that could lead to infinite recursion.

The bug.py file contains a factorial function that is not robust enough to handle negative input. Running this code with a negative number results in a RecursionError.

The bugSolution.py file shows the corrected version of the factorial function, handling this edge case properly.

This example highlights the importance of careful input validation and error handling when using recursion.

About

This code demonstrates a common error in recursive functions: forgetting to handle negative input. The factorial function is only defined for non-negative integers. Calling it with a negative number leads to infinite recursion and a RecursionError.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages