Welcome to the forums! For the future, please use the code tags around your script to make it easier to read :) ( http://www.daniweb.com/forums/announcement114-3.html )
This does look like a homework question, so please read the rules about posting homework questions here: http://www.daniweb.com/forums/announcement114-2.html
Here is an example for comming up with prime numbers (up to 1230):
I commented to show you the logic I used, and how it's done..
>>> def getprimes(x):
primes = []
# Loop through 9999 possible prime numbers
for a in range(1, 10000):
# Loop through every number it could divide by
for b in range(2, a):
# Does b divide evenly into a ?
if a % b == 0:
break
# Loop exited without breaking ? (It is prime)
else:
# Add the prime number to our list
primes.append(a)
# We have enough to stop ?
if len(primes) == x:
return primes
>>> getprimes(5)
[1, 2, 3, 5, 7]
>>> getprimes(7)
[1, 2, 3, 5, 7, 11, 13]
Another cool way of doing this (and because i like complicated lists):
>>> [p for p in [a for a in range(1,1000) if all([(a % b != 0) for b in range(2, a)])][:input('How many prime numbers? ')]]
How many prime numbers? 10
[1, 2, 3, 5, 7, 11, 13, 17, 19, 23]
>>>
That way is slower because it will allways create a full list of prime numbers (169 of them) and then just give you the ones you ask for... But its fun to work out loops like that :)