Created
January 25, 2021 19:46
-
-
Save raymondberg/22cedfab9a5d29efbe82a33f1e5df00e to your computer and use it in GitHub Desktop.
My First Python Scripts were written on Jan 4 of 2007. Here they are for posterity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import count | |
def generate_primes(stop_at=None): | |
primes = [] | |
for n in count(2): | |
if stop_at is not None and n > stop_at: | |
return | |
composite = False | |
for p in primes: | |
if not n % p: | |
composite = True | |
break | |
elif p**2 > n: | |
break | |
if not composite: | |
primes.append(n) | |
yield n | |
for i in generate_primes(): # iterate over ALL primes | |
if i > 100: break | |
print i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
def getline(): | |
return sys.stdin.readline() | |
print 'What is your name?' | |
name = getline() | |
print 'I think you said your name was %s' % name | |
print 'Did I get that right?' | |
response = getline() | |
if(response == 'Yes'): | |
print 'Yay for me' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment