3 ms·
Seems to work for a factorial function also Perform a code review of the following module, identifying any bugs: ``` #!/usr/bin/env python3 def factori
by zitterbewegung 4y ago
Seems to work for a factorial function also
Perform a code review of the following module, identifying any bugs:
```
#!/usr/bin/env python3
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
# recursive call to the function
return (x * factorial(x+1))
```
A: The bug in this code is that the function is attempting to find the factorial of an integer by recursively calling itself with an incremented value. This will cause an infinite loop.
But if you unindent and then also perform the n+1 error it only will see the unindent issue.
Perform a code review of the following module, identifying any bugs:
```
#!/usr/bin/env python3
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
# recursive call to the function
return (x * factorial(x+1))
```
A: The code will not run because there is a syntax error on line 6. The indentation is incorrect. The return statement should not be indented.