[Edu-sig] Hello from a CS Teacher
Steve Litt
slitt@troubleshooters.com
Sat, 12 Feb 2000 13:56:43 -0500
At 04:59 PM 02/11/2000 -0800, Kirby Urner wrote:
Kirby -- your program worked nicely on my Red Hat box. I'd like to try
writing a program that outputs music through the computer case's built in
speaker. Does anyone know of a python command to output a frequency to the
built in speaker, or do you know an OS call to do it?
Thanks
Steve
Steve Litt
Webmaster, Troubleshooters.Com
http://www.troubleshooters.com
slitt@troubleshooters.com
>MODULE: seive.py
>
>primes = [2] # dynamic list of primes
>
>def get2nb(nbprimes):
> # return list of primes
> # nbprimes = number of primes to list
>
> global primes # keep at module level for re-use
>
> # chop the list if already longer than we need
> if len(primes)>nbprimes: primes = primes[:nbprimes]
>
> # start with highest prime so far
> i = primes[-1]
>
> while len(primes)<nbprimes:
> if addprime(i): primes.append(i)
> # skip even numbers (only 2 is prime)
> if i==2: i=i+1
> else: i=i+1
>
> return primes
>
>def addprime(n):
> # internal seive to check whether a number is prime
>
> verdict = 1 # default is "yes, add to list"
>
> for i in primes:
> if (i==n) | (n%i == 0): # is prime or no remainder
> verdict = 0 # so we _don't_ want to add
> break
> if i**2 > n: # stop trying to divide by
> break # lower primes when p**2 > n
>
> return verdict
>
>In action:
>
>>>> reload(seive)
><module 'seive' from 'G:\Python\seive.py'>
>>>> seive.get2nb(10)
>[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>>>> seive.get2nb(5)
>[2, 3, 5, 7, 11]
>>>> seive.get2nb(30)
>[2, 3, 5, 7, 11, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
>53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]
>
>
>
>_______________________________________________
>Edu-sig mailing list
>Edu-sig@python.org
>http://www.python.org/mailman/listinfo/edu-sig
>