A simple while loop works, just make sure you divide the number by 2, otherwise you’ll get the NEXT power of 2.
def function(number):
x = 1
while x <= number:
x *= 2
return x / 2
solved Defining function with an argument, employs while loop and returns largest power of 2 that is less than or equal to number [closed]