import randomdef getnum() : return int(raw_input("your guess? "))def match(guess, secret) :r = ( guess < secret and 'too low') or ( guess > secret and 'too high') or (guess == secret and 'You win!!')print rreturn rdef loop(x,z):print "try #",z,return ('You win!!' != match(getnum(),x) and loop(x,z+1) ) or (z)def guessnumber():secret = random.choice(range(101))times = loop(secret,1)print "Total # of try's = ",timesprint (times < 3 and "no way!!") or (times < 4 and "very good") or (times < 6 and 'slo-po') or (times > 5 and 'looser!!')return
May the Source be with You
Thursday, June 28, 2012
Guess my number the functional way
Guess my number on python the functional way:
Wednesday, June 27, 2012
Calculating the scrabble value of a word
def scrabble_value(word):if len(word)==1:
return 0
val=dict(a=1,b=3,c=3,d=2,e=1,f=4,g=2,h=4,i=1,j=8,k=5,l=1,m=3,n=1,o=1,p =3,q=10,r=1,s=1,t=1,u=1,v=4,w=4,x=8,y=4,z=10)
return reduce(lambda x,y:x+y,map(lambda x:val[x],word))
Flying trucks over Texas..
While chatting with a client I happened to mention a tornado that sent trucks flying not to far from where I live.. I had the feeling that he thought I was exaggerating..
Nope, we don't exaggerate here in Texas.. ;)
Nope, we don't exaggerate here in Texas.. ;)
Subscribe to:
Posts (Atom)