def listgenerator(x):
x=1
while x>0:
x+=1
print(x)
print(listgenerator(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))
Another question, whats the easiest way to find out if a list contains integers?
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
def listgenerator():
x=1
while x > 0:
x+=1
if x%2==0:
print (x)
else:
return
listgenerator()
def listgenerator():
x=1
while x > 0:
x+=1
if x%2!=0:
print (x)
else:
return
listgenerator()
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.