0
def square(x):
  return x * x

def twoPower(x, n):
  while n > 1:
  x = square(x)
  n = n/2
return x

twoPower(2, 8) gives 256 when we bind x = 5, n = 1. Why?

Mazdak
  • 105,000
  • 18
  • 159
  • 188
Eliza
  • 101
  • 1
  • 1
  • 9
  • 1
    "when we bind x = 5, n = 1" - where are you binding those? – user2357112 Jun 19 '15 at 13:52
  • 1
    Why would `twoPower(2, 8)` be anything *other* than `256`? – jonrsharpe Jun 19 '15 at 13:54
  • No, I do not understand what exactly is scoping and does global environment mean everything outside of the function, and local environment means everything inside the function? – Eliza Jun 19 '15 at 13:57
  • @user2357112- while writing in the python interpreter, suppose we give: x = 5, n = 1 and twoPower(2, 8) – Eliza Jun 19 '15 at 13:58

0 Answers0