On Wednesday, August 16, 2017 at 12:45:13 PM UTC+1, Steve D'Aprano wrote: > On Wed, 16 Aug 2017 09:06 pm, Stefan Ram wrote: > > > 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) > > My initial prediction was: > > > 4 > 1 > 2 > 16 > > > which is embarrassing. Fortunately my supper arrived in the nick of time > to distract me from hitting Send, just long enough to remember that 1*1 > is 1, not 2. > > So how about: > > 4 > 1 > 2 > 4 > > Unless its a syntax error... I can't remember if the REPL allows multiple > semi-colon separated statements after a colon declaration. I know it gets mad > at this: > > py> def a(): pass; def b(): pass > File "<stdin>", line 1 > def a(): pass; def b(): pass > ^ > SyntaxError: invalid syntax > > > So my wild guess is that this is a trick question and the actual answer is > that > its a SyntaxError. > > Otherwise, I'm sticking with > > 4 > 1 > 2 > 4 > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse.
How do you expect to get four lines of output from the three function calls? Kindest regards. Mark Lawrence. -- https://mail.python.org/mailman/listinfo/python-list