0

def T2(x):
return x * 2
def dozen():
return T2('12')
def enestrate():
return T2(3)
print int (dozen()) + enestrate()


I know it prints 1218 but i dont understand the code and the whole concept ... I used python to run it

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by BestJewSinceJC
0

Trace it out.

1)

//returns 2 times the number passed in
def T2(x):
return x * 2

2)

//return T2(12) = 12*2 = 24
def dozen():
return T2('12')

3)

//returns T2(3) = 2*3 = 6
def enestrate():
return T2(3)

now this call :

print int (dozen()) + enestrate()

Split it up and analyze it. See what you can come with.

0

Trace it out.

//return T2(12) = 12*2 = 24
def dozen():
    return T2('12')

Split it up and analyze it.

I bet you didn't.
(Hint: T2('12') returns '1212'

1

It passed in a String... T2('12').. scripting languages support operator overloading (I think that's the term)
Had it passed in an int you would've been right

Edited by BestJewSinceJC: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.