A small quiz question

Ian Kelly ian.g.kelly at gmail.com
Wed Aug 16 13:28:20 EDT 2017


On Wed, Aug 16, 2017 at 6:51 AM, Dennis Lee Bieber
<wlfraed at ix.netcom.com> wrote:
> On 16 Aug 2017 11:06:26 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
>
>>  I wrote my first Python quiz question!
>>
>>  It goes like this:
>>
>>  Can you predict (without trying it out) what the Python
>>  console will output after the following three lines have
>>  been entered?
>>
>>def f(i): print(i); return i;
>>
>>f(4)**f(1)**f(2)
>>
>
>         As a first guess
>
> 2
> 1
> 4
>
> 4
>
> since in many languages, exponentiation associates right to left

I thought the same thing but figured there was no reason to eval f(2)
before f(1), so I came up with

1
2
4
4

which is also wrong.



More information about the Python-list mailing list