Instantly share code, notes, and snippets.

View verbose_baseconv.py
num_tested = int(input())
while num_tested < 1:
num_tested = int(input())
print("= ", end='')
is_first_print = True
total =0 ; c = 0 ; K = 1
while K < num_tested:
c += 1 ; K = 1<<c
for n in range(K):
prod = num_tested&(1<<n);
View day_31.py
# a dumb game. How to win this?
import random
import time
import sys
t0 = time.time()
while True:
if random.choice((True,False)):
time.sleep(0.13)
else:
time.sleep(0.29)
View day_30.py
import pygame
from time import sleep
import random
from math import cos,sin,pi
DISP_WIDTH = 800
DISP_HEIGHT = 600
class Player:
'''models a moving player representation that can move left or right'''
BASECOLOR = pygame.Color('darkred')
View day_29.py
from random import choice
mid_names = [ "" for i in xrange(7) ]
mid_names.extend( [ "Kindred", "Junior", "Senior", "Jack" ])
first_names = \
[ "Tiger", "Mike", "Edgar", "Jean-Paul", "Sandra", "Clara", "Gary", "Philip", "Edwin" ]
last_names = [ "Woods", "Jackson", "Nelson", "Watson", "Palmer", "Hagen", "Nicklaus", "Haeger", "de LaMartre" ]
def printRandomName():
mid = choice(mid_names)
View day_28.py
import random
import time
def detPrecision( candidate, model):
chars_cand = list( candidate)
chars_model = list(model)
while( len(chars_cand)<len(chars_model) ):
chars_cand.append(' ')
while( len(chars_cand)>len(chars_model) ):
chars_cand.pop()
View day_27.py
import re
print "Testing your knowledge on regular expressions"
partterns = [
"a{4,}b", "Y.*g", "ro..c..ter", "[a,m,k]{5,8}" ]
for pat in partterns:
print "Try to type a string that matches the REGULAR EXPRESSION",pat
success = False
while True:
user_str = raw_input()
View day_26.py
# this code is awesome, you will see it everywhere!
import sys
import random
import os
alphabet = [chr(i) for i in range(ord('a'),ord('z') + 1) ]
def genRandomName():
name_length = random.randint(2,8)
lchar = list()
for i in xrange(name_length):
View day_25.py
import pygame
DISP_WIDTH = 640
DISP_HEIGHT = 480
def refreshScreen():
window.fill( pygame.Color('black') )
pygame.display.flip()
# init. pygame libr; create the screen and diplays a help message in the console
View day_24.py
import pygame
from time import sleep
import random
from math import cos,sin,pi
DISP_WIDTH = 800
DISP_HEIGHT = 600
class MobileElement:
MOMENTUM = 0.985
'''abstract class representing something that moves'''
View day_23.py
# This shows how we can define and use a META-function in python
def produce_incrementor( step):
''' it produces various increment functions'''
return lambda u:u+step
print "three by three"
increm_three = produce_incrementor(3)
k=0
while k < 34: