def fibs(num):
'This is used to compose Fibs-NumSeq...'
result = [0, 1]
for i in range(8):
result.append(result[-2] + result[-1])
return result
num = input("Please input a intenger for fibs()...")
assert 0 < num
print "The fibs( " + str(num) + " ) is :" , fibs(num)
print"\n****Parameter Test****\n"
a = 1
print "id(a) : ", id(a)
print "a = ", a
def ichange(x):
x += 1
print "id(): ", id(x)
print "int_change(): ", x
ichange(a)
print "a = ", a
lst = [1, 2, 3, 4, 5, 6]
print "lst is : ", lst
def lchange(x):
x[0] = 9
print "lst_change(): ", x
lchange(lst)
print "lst is : ", lst
print "\n****Scope Test****\n"
def scope():
global a
a *= 2
print "scope(): ", a
scope()
print "a = ", a
num = input("Please input the num what U want: ")
seq = []
for i in range(50):
seq.append(int(random.uniform(1, 100)))
print seq, '\n\n'
seq.sort()
print '\n\n', seq
high = len(seq) - 1
low = 0
def search(seq, num, low, high):
if low == high:
if num == seq[low]:
print "Found it: ", num
return num
else:
print "No Found!"
return 0
else:
middle = (low + high) / 2
if num > seq[middle]:
print num, ' > ', seq[middle]
search(seq, num, middle + 1, high)
else:
print num ,' <= ', seq[middle]
search(seq, num, low, middle)