Help with code

Status
Not open for further replies.

gamer_girl09

Veteran
Veteran
Joined
May 1, 2015
Messages
63
Reaction score
7
First Language
english
Primarily Uses
RMMV
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()
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
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.
 

mjshi

Jack of Most Trades
Veteran
Joined
Feb 16, 2013
Messages
969
Reaction score
808
First Language
English
Primarily Uses
N/A
@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).
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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
 

gamer_girl09

Veteran
Veteran
Joined
May 1, 2015
Messages
63
Reaction score
7
First Language
english
Primarily Uses
RMMV
@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...
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

mjshi

Jack of Most Trades
Veteran
Joined
Feb 16, 2013
Messages
969
Reaction score
808
First Language
English
Primarily Uses
N/A
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.
 
Last edited by a moderator:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,377
Reaction score
8,536
First Language
English
Primarily Uses
RMMV
As this is not a forum for asking general code questions, but those specifically related to RPG Maker programs, I'm closing this.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top