+ 1

Can someone help sith this python recursion?

def convert(num): return (num % 2 + 10 * convert(num // 2))

11th Jun 2024, 9:57 PM
Marina Nikolic
Marina Nikolic - avatar
2 Respostas
+ 6
# Hi, Marina Nikolic! # You just have to add a base case: def convert(num): # Base case: if the number is 0, return 0. if num == 0: return 0 else: # Recursive case: compute binary representation. return num%2 + 10*convert(num // 2) # Test the function with an example. print(convert(5)) # Expected output: 101
11th Jun 2024, 10:31 PM
Per Bratthammar
Per Bratthammar - avatar
+ 5
To sith it, you must show it the power of the dark side.
11th Jun 2024, 10:21 PM
Wilbur Jaywright
Wilbur Jaywright - avatar