Function

1.scope
  • inside a function,can access a variable defined outside

  • inside a function,cannot modify a variable defined outside

2.default value

3.hanoi
def printMove(fr, to):
    print('move from ' + str(fr) + ' to ' + str(to))

def Towers(n, fr, to, spare):
    if n == 1:
        printMove(fr, to)
    else:
        Towers(n-1, fr, spare, to)
        Towers(1, fr, to, spare)
        Towers(n-1, spare, to, fr)

print(Towers(4, 'P1', 'P2', 'P3'))
4.Module & File

results matching ""

    No results matching ""