30
Oca

Örnek1: Simple Example

a = 2print a,7,'eve'

Örnek2: Factorial

def myFactorial(n):    if(n<1):        print 'end of the computation'        return 1    return n * myFactorial(n-1)

print myFactorial(5)

Örnek3: Double Factorial

#Seval Unver 2009-10-08def myDoubleFactorial(n):    if(n <= 0):        print 'end of the computation'        return 1

    if(n % 2 == 1):        if(n <= 1):            print 'end of the computation'            return 1        return n * myDoubleFactorial(n-2)

    if(n % 2 == 0):        if(n < 1):            print 'end of the computation'            return 2        return n * myDoubleFactorial(n-2)

    return 0

print myDoubleFactorial(5)

Örnek4: Split

#Seval Unver 2009-10-08def mysplit(word, split):    list = []    part = ''    for x in word:            if not (x == split):                part += x            else:                list += [part]                part=''

    list += [part]                return list        

print mysplit('eb334mlpjiefwxuhbnlaxz7xknxnjn','x')

Örnek5: Chritsmas Tree

#Seval Unver 2009-10-08def xtree(star, length):    var = ''    for row_number in range(1,length):        for y in range (1,length-row_number+1):            var +=" "        for z in range (1, 2*row_number):            var +=star        print var        var = ''

xtree('*',4) 

***

Share and Enjoy: Twitter Facebook FriendFeed Tumblr Google Bookmarks del.icio.us LinkedIn email Identi.ca MySpace StumbleUpon Technorati Posterous RSS Reddit Digg Yahoo! Buzz Yahoo! Bookmarks blogmarks Suggest to Techmeme via Twitter Netvibes Live