The program is supposed to take as input a list and return the index of the values less than 0.
I’m not allowed to use for loops, however. I have to do it using a while loop.
For example, if my function were named findValue(list) and my list was [-3,7,-4,3,2,-6], it would look something like this:
>>>findValue([-3,7,-4,3,2,-6])
would return
[0, 2, 5]
So far, I have tried:
def findValue(list):
under = []
length = len(list)
while length > 0:
if x in list < 0: #issues are obviously right here. But it gives you
under.append(x) #an idea of what i'm trying to do
length = length - 1
return negative
I made some small changes to your code. Basically I’m using a variable
ito represent the index of elementxin a given iteration.