-
Description the test inputs are wrong, because you can check only using the modulus operation, if it was created correctly 30 shouldn't be assign as true, but it only test results from 2 exponentiation
Code def power_of_two( n ): if n % 2 == 0: return True else: return False
Test Cases from random import randint for x in range(5): n = 2 ** randint( 21, 25 ) test.assert_equals( power_of_two(n), True ) for x in range(5): n = 2 ** randint( 21, 25 )+(-1) ** randint( 1, 4 ) test.assert_equals( power_of_two(n), False )
Output:
-
Code - def power_of_two( n ):
return n & ( n - 1 ) == 0- if n % 2 == 0: return True
- else: return False
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}