Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PYTHON 3.3] Need a bit help.

Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
Its an infinite list atm which starts at number 2, but what i wanna do is cut out every second number after it. So like 2 3 5 7. But i can't figure it out.

Code:
def listgenerator(x):   
    x=1
    while x>0:
        x+=1
        print(x)
            
print(listgenerator(1))
 
hello
Loyal Member
Joined
Jun 24, 2004
Messages
726
Reaction score
158
Its an infinite list atm which starts at number 2, but what i wanna do is cut out every second number after it. So like 2 3 5 7. But i can't figure it out.

Code:
def listgenerator(x):   
    x=1
    while x>0:
        x+=1
        print(x)
            
print(listgenerator(1))

Since it does look like your homework and rules say that we aren't here to do your homework, I will just give you a tip: modulo
 
Joined
May 23, 2008
Messages
1,071
Reaction score
574
We're not here to do your homework for you, buddy. Use search engine, your classmates, and even your professor. Unless of course you were blatantly not listening to what he/she was saying. If that's the case, maybe the class isn't for you.
 
Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
No, it's not my homework, i don't study programming in school :). And i wasn't looking for a solution, i was looking for a tip, thanks danse.
 
Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
Another question, whats the easiest way to find out if a list contains integers?
 
hello
Loyal Member
Joined
Jun 24, 2004
Messages
726
Reaction score
158
Another question, whats the easiest way to find out if a list contains integers?

Whole thread about it, find the way that suits you most.
 
Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
Can't use any of those for a list or im just doing it wrong?

x=20
def divider(x):
for variable in range(2, (x-1)):
newx=x/variable
if newx.is_integer():
return True
if newx.is_integer()==False:
return False

i wanted it to divide x in the range of 2 to (x-1) and check if any of the divisions return an integer, but i think it only divides it with the first range item before going to next x(also using x in parent(?)loop)? hope you understand xD
 
Best Commu NA
Loyal Member
Joined
Sep 12, 2007
Messages
507
Reaction score
38
If this was for school, I doubt your teacher gave you three days or more too hand it in.
Here you go.


Prints Even Numbers:

Code:
def listgenerator():   
    x=1
    while x > 0:
        x+=1
        if x%2==0:
            print (x)
    else:
        return


listgenerator()

Prints Odd Numbers:

Code:
def listgenerator():   
    x=1
    while x > 0:
        x+=1
        if x%2!=0:
            print (x)           
    else:
        return


listgenerator()

Next time use Google, I found it in the first result.
 
Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
Thank you for you answer, but danse already answered it. Problem is i need to check if x%(range(2, x-1))==0, but it doesn't let me use the range command nor list in it. So i don't really understand how to do that (X_X)'.
 
hello
Loyal Member
Joined
Jun 24, 2004
Messages
726
Reaction score
158
Thank you for you answer, but danse already answered it. Problem is i need to check if x%(range(2, x-1))==0, but it doesn't let me use the range command nor list in it. So i don't really understand how to do that (X_X)'.

I think you may have to import Math library into your script, but not sure it's been a while I've used Python and it's not my main language to be honest.
 
Newbie Spellweaver
Joined
Feb 21, 2013
Messages
6
Reaction score
1
I think you may have to import Math library into your script, but not sure it's been a while I've used Python and it's not my main language to be honest.

didn't help :(
 
Back
Top