Skip to content

Instantly share code, notes, and snippets.

View jonathanpike's full-sized avatar

Jonathan Pike jonathanpike

  • Fullscript
  • St. Albert, Alberta
View GitHub Profile
# from http://www.practicepython.org/exercise/2014/03/26/08-rock-paper-scissors.html
def rps():
playagain = "yes"
print "It's Rock, Paper, Scissors time!"
while playagain == "yes":
player1 = raw_input("Player 1 - What do you choose? ")
player2 = raw_input("Player 2 - What do you choose? ")
# from http://www.practicepython.org/exercise/2014/04/02/09-guessing-game-one.html
import random
def chkguess():
stop = "go"
guessnum = 0
while stop == "go":
guess = int(raw_input("Choose a number between 1 and 9: "))
# from http://www.practicepython.org/exercise/2014/04/10/10-list-overlap-comprehensions.html
import random
# a = random.sample(range(1,1000), 20)
# b = random.sample(range(1,1000), 30)
a = [1, 1, 3, 5, 6, 7, 8, 10]
b = [1, 1, 6, 7, 10, 14, 17, 18]
# from http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html
def is_prime(num):
print "Checking if %d is Prime" % num
numrange = [x for x in range(2,num)]
count = 0
for i in numrange:
if num % i != 0:
count = count
# from http://www.practicepython.org/exercise/2014/04/25/12-list-ends.html
import random
def first_and_last(l):
new_list = l[::len(l)-1]
""" This specifies the "step" -- takes the first item,
skips the length of the list less 1, and therefore gives
you the last item """
# from http://www.practicepython.org/exercise/2014/04/30/13-fibonacci.html
def fibonacci():
num = int(raw_input("How many numbers of the Fibonacci sequence do you want? "))
seq = [0, 1]
count = 2
if num == 0:
print "Please provide a a number greater than 0"
# from http://www.practicepython.org/exercise/2014/05/15/14-list-remove-duplicates.html
def removedupes(list):
new_list = []
for i in list:
if i not in new_list:
new_list.append(i)
else:
pass
print new_list
# from http://www.practicepython.org/exercise/2014/05/15/14-list-remove-duplicates.html
def removedupesset(testset):
new_set = set(testset)
print new_set
test = [1, 1, 2, 3, 5, 5, 5, 6, 7, 8, 8, 9]
removedupesset(test)
# from http://www.practicepython.org/exercise/2014/05/21/15-reverse-word-order.html
def reversestring():
usr = raw_input("Give me a string and I will reverse it. ")
split = usr.split()
sentence_rev = " ".join(reversed(split))
print sentence_rev
reversestring()
# from http://www.practicepython.org/exercise/2014/05/28/16-password-generator.html
import random
import string
def genpass():
lower_letters = list(string.ascii_lowercase)
upper_letters = list(string.ascii_uppercase)
symbols = list(string.punctuation)
num = list(range(1,9))