Reputation: 113
quys i am totally new to programming so please help me ... i am trying to make a function produce all the prime numbers and put it in list and generate a ranodm number from this list ... here is my code
from random import choice
question_3():
list = []
for i in range(2,20):
flag=True
for num in list:
if(i%num==0):
flag=False
if(flag):
list.append(i)
p = choice(list)
print list , p
question_3()
but an error appeared
SyntaxError: invalid syntax
Upvotes: 0
Views: 111
Reputation: 33046
You are missing a def
before the function name:
def question_3():
for i in range(2,20):
#...
Upvotes: 2
Reputation: 2576
from random import choice
def question_3():
list = []
for i in range(2,20):
flag=True
for num in list:
if(i%num==0):
flag=False
if(flag):
list.append(i)
p = choice(list)
print list , p
question_3()
Upvotes: 1
Reputation: 13222
You missed the def
before the definition of the function question_3
.
Some additional comments: Please get rid of the unnecessary parens when you use an if-statement and don't use list
as a variable name because you shadow the builtin list
.
Reading PEP-8, the Style Guide for Python Code, might be a good idea.
Upvotes: 1