Debugging Challenge: Factorial Function with Base Conversion v2 (retired)
Description:
Factorial Function with Base Conversion (v2) - Debugging
In this challenge, you must implement a function that calculates the factorial of a given non-negative integer. The function should also support an optional parameter that allows the user to specify a base for the output.
Requirements:
The function must raise ValueError for negative inputs.
If the base parameter is provided, the function should return the factorial in that base as a string.
If no base is provided, the function should return the factorial in base 10.
The base must be at least 2; otherwise, a ValueError should be raised.
Ensure that the function works efficiently, especially for larger inputs.
The base conversion should properly handle large factorials and return the correct representation.
Additional Considerations:
Handle edge cases such as 0! (factorial of 0) correctly, which should return 1 in any base.
Test cases should cover both valid inputs (positive integers and valid bases) and invalid inputs (negative numbers or invalid bases).
For large inputs, consider the efficiency of the factorial calculation and base conversion.
Identify and fix the bugs in the initial implementation, ensuring that the function works and passes all test cases.
Good luck, have fun!
Similar Kata:
Stats:
Created | Oct 5, 2024 |
Warriors Trained | 10 |
Total Skips | 0 |
Total Code Submissions | 31 |
Total Times Completed | 10 |
Python Completions | 10 |
Total Stars | 0 |
% of votes with a positive feedback rating | 50% of 9 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |