I was attempting a leetcode problem. Here I had to count the number of steps until the variable num
is equal to 0
. Here is my code:
class Solution:
def numberOfSteps(self, num: int) -> int:
step = 0
while num != 0:
num //= 2 if not num%2 else num -= 1
step += 1
return step
Here is the error from the console output:
File "/home/syswraith/main.py", line 3
num //= 2 if not num%2 else num -= 1
^^
SyntaxError: invalid syntax
Can anyone point out what I am doing wrong? Thanks in advance 🙂