๐ Bug of the day
AI Attempt: Reversing a negative number crashes
mediumAn AI assistant wrote this for a classic interview question. reverse_number(n) reverses the digits of a whole number and keeps its sign. Example: reverse_number(123) โ 321, reverse_number(-123) โ -321.
What happens: reverse_number(-123) crashes: ValueError: invalid literal for int() with base 10: '321-'.
def reverse_number(n):
return int(str(n)[::-1])Open with hints โRuns in your browser. No account needed.
Debugging practice from TryBugHunt, free, in your browser.