Help with code

Spoiler
import random


loop = 0
loop2 = 0


def sequentialSearch(alist, item):
        found = False
    
        while loop2 < len(alist) and not found:
            if alist[pos] == item:
                found = True
            else:
                pos = pos+1
    
        return found
while loop < 50:    
    randlist = (random.randint(0,100) for _ in range(100))
    while loop2 < 10:
        rannum = (random.randint(0,100) for _ in range(10))
        print(sequentialSearch(randlist, rannum))





 




the spoiler has the code i am trying to get working... the error i am getting is:


TypeError: object of type 'generator' has no len()
I've moved this thread to Learning JavaScript. Please be sure to post your threads in the correct forum next time. Thank you.



Also next time state what language the code is in. I had to assume JavaScript due to your profile, but if that is Ruby we'll have to move it again.
@bgillisp This code actually appears to be in python. Characteristics: the colon 🙂) and import random, random.randint().


@gamer_girl09 could you explain what you're attempting to do? To me, it looks like you're trying to make a function that returns True if an item is found in the list, False if not. Is that correct?


Edit: if so, then just use (rannum in ranlist), or, if you insist on a function, just do return (item in alist).
I would have thought Ruby given the def.  But there's no : in Ruby after method definitions and while statements and loops.


If it's Python you're in the wrong place - this is an RPG Maker forum, and no RPG Makers use Python.


If it's Ruby, try alist.size
@bgillisp This code actually appears to be in python. Characteristics: the colon 🙂) and import random, random.randint().


@gamer_girl09 could you explain what you're attempting to do? To me, it looks like you're trying to make a function that returns True if an item is found in the list, False if not. Is that correct?


Edit: if so, then just use (rannum in ranlist), or, if you insist on a function, just do return (item in alist).





 

@mjshi yeah it's supposed to return true if the number is in the list and false if it isn't

I would have thought Ruby given the def.  But there's no : in Ruby after method definitions and while statements and loops.


If it's Python you're in the wrong place - this is an RPG Maker forum, and no RPG Makers use Python.


If it's Ruby, try alist.size





 

@Shaz I use python to test an idea out then i convert it to either java or C# depending on the program i am using... i haven't taken the time to really mess with ruby...
None of the RPG Makers use Java or C# either.


The subforum you've posted in is Learning Javascript. The forum you're on is the RPG Maker forum, and if you're using Python, Java or C#, then you're not requesting help with any of the RPG Makers.  Javascript and Ruby are the only languages used by the RPG Makers.  If you're not using either of those, perhaps there are other forums or sites where you can get help.
def sequentialSearch(alist, item):
return item in alist


That's all you need. Next time, try asking this sort of question in StackOverflow, you're more likely to get the answer you're looking for there.
As this is not a forum for asking general code questions, but those specifically related to RPG Maker programs, I'm closing this.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-code.72173/