python 3.x - Converting a for loop into a while loop -
i've done loop returns true if there 2 next 2 , i'm trying using while loop. can't seem make while loop work.
here's loop i've done
def has22(nums): "return true if array contains 2 next 2 somewhere""" in range(0, len(nums)-1): if nums[i] == 2 , nums[i+1] == 2: return true return false
i tried running while loop doesn't work.
def has22(nums): """while loop version""" = 0 while < len(nums) - 1: if nums[i] == 2 , nums[i+1] == 2: return true += 1
can please tell me what's wrong it?
the
return true
not indented, it's returned (ie. not body ofif
statement)the function never returns `false
try:
def has22(nums): """while loop version""" = 0 while < len(nums) - 1: if nums[i] == 2 , nums[i+1] == 2: return true += 1 return false
Comments
Post a Comment