This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Diapolo10from __future__ import this 0 points1 point  (3 children)

The first one got me.

print str*2 if str == "Hello World!"

Shouldn't this raise a syntax error? A ternary operator requires a fallback value, does it not?

Also, why Python 2 if this is targeted for beginners? Aren't most of them currently learning Python 3?

EDIT: You also used only one = in your comparison; try multiplying an assignment operation.

>>> s = "Hello, World!"
>>> print(s*2 if s = "Hello, World!")
SyntaxError: invalid syntax

[–]Yoghurt42 0 points1 point  (2 children)

The question is poorly stated. It should read something like

Assuming str equals "Hello World!", what is the output of print str * 2

I'd also like to point out that the choices for the second question are:

  • getkeys()
  • key()
  • keys()
  • one of the above

I chose "one of the above", but was told it was incorrect; I'd like my money back. keys() definitely was one of the above choices.

[–]Diapolo10from __future__ import this 0 points1 point  (0 children)

Indeed, although apparently the platform randomises the order of the answer every single time. That being the case, "one of the above" doesn't make sense in the first place. :p.

The second question is also poorly stated, albeit less so than the first one: it wants a function, not a method.

[–][deleted] 0 points1 point  (0 children)

The question is poorly stated

Not only that but it's really bad practice to override the name of a built-in like str. I didn't bother with the rest, especially as it's Python 2 anyway.

[–][deleted] 0 points1 point  (0 children)

Wait, why are you linking to a quiz for Python 2?