Show off your Python chops and compete with others

  • Thread starter Nathaniel Sokoll-Ward
  • Start date
N

Nathaniel Sokoll-Ward

Thought this group would appreciate this: www.metabright.com/challenges/python

MetaBright makes skill assessments to measure how talented people are at different skills. And recruiters use MetaBright to find outrageously skilled job candidates.

Python is a new area of expertise for us. We make "Challenges" for a bunch of languages and we're excited to finally have Python released. Give it a shot -- I'd love to hear what you think.
 
A

Andrew Cooper

Thought this group would appreciate this: www.metabright.com/challenges/python

MetaBright makes skill assessments to measure how talented people are at different skills. And recruiters use MetaBright to find outrageously skilled job candidates.

Python is a new area of expertise for us. We make "Challenges" for a bunch of languages and we're excited to finally have Python released. Give it a shot -- I'd love to hear what you think.

"What is the correct number of spaces for indentation in Python?"

I presume the question should be more along the lines of "What does PEP8
say?", because all answers are correct.

"String literals are written with what?"

The answer is not "ALl of these answers are correct"


So two of of 7 questions with wrong answers so far...

~Andrew
 
R

Roy Smith

Andrew Cooper said:
"What is the correct number of spaces for indentation in Python?"




What does the following code do?
def a(b, c, d): pass

My answer: "Defines a function which returns None", but that isn't one
of the choices.
 
A

Andrew Cooper

What does the following code do?
def a(b, c, d): pass

My answer: "Defines a function which returns None", but that isn't one
of the choices.

"Which is a correct way to perform exponentiation in Python?"

1) math.pow(a,b)
2) a^b
3) a*2b
4) None of the other responses are correct

Apparently I was wrong by answering 4), and 1) is the expected answer.
Clearly the author doesn't know about the ** operator in python.


It appears that no serious python coders were consulted when writing
these questions.

~Andrew
 
C

Chris Angelico

Thought this group would appreciate this: www.metabright.com/challenges/python

MetaBright makes skill assessments to measure how talented people are at different skills. And recruiters use MetaBright to find outrageously skilled job candidates.

Python is a new area of expertise for us. We make "Challenges" for a bunch of languages and we're excited to finally have Python released. Give it a shot -- I'd love to hear what you think.

"""How could you open a file c:\scores.dat to write in binary?

outfile = open("c:\\scores.dat", "w")
outfile = open("c:\scores.dat", "a")
outfile = open("c:\\scores.dat", "w")
outfile = open("c:\\scores.dat", "wb")"""

Not technically wrong, but stylistically suspect; I would recommend
using forward slashes (which work fine on Windows) and avoiding the
drive letter, both of which avoid making your example
Windows-specific. (At least, I don't think there are any other
platforms Python supports that use drive letters; OS/2 support was
dropped a little while ago, though I believe Paul Smedley still
maintains a port. But I digress.)

"""Which method will write a pickled representation of the object to
an open file?"""

Method names without object names aren't all that useful. Do you mean
"Which method of the pickle module..."?

"""From which languages are Python classes derived from?"""

Sounds like Python history trivia more than a coding challenge, but if
that's what you want to go for, sure.

ChrisA
 
C

Chris Angelico

Thought this group would appreciate this: www.metabright.com/challenges/python

MetaBright makes skill assessments to measure how talented people are at different skills. And recruiters use MetaBright to find outrageously skilled job candidates.

Python is a new area of expertise for us. We make "Challenges" for a bunch of languages and we're excited to finally have Python released. Give it a shot -- I'd love to hear what you think.

By the way, here's a fairly bad solution to your final question:

array666=lambda x:b"\6\6\6" in bytes(x)

Works for the given test-cases! Doesn't work with arrays at all,
despite the description.

ChrisA
 
M

MRAB

"""How could you open a file c:\scores.dat to write in binary?

outfile = open("c:\\scores.dat", "w")
outfile = open("c:\scores.dat", "a")
outfile = open("c:\\scores.dat", "w")
outfile = open("c:\\scores.dat", "wb")"""

Not technically wrong, but stylistically suspect; I would recommend
using forward slashes (which work fine on Windows) and avoiding the
drive letter, both of which avoid making your example
Windows-specific. (At least, I don't think there are any other
platforms Python supports that use drive letters; OS/2 support was
dropped a little while ago, though I believe Paul Smedley still
maintains a port. But I digress.)

"""Which method will write a pickled representation of the object to
an open file?"""

Method names without object names aren't all that useful. Do you mean
"Which method of the pickle module..."?

"""From which languages are Python classes derived from?"""
Does it really have the word "from" twice?
 
C

Chris Angelico

Does it really have the word "from" twice?

You know, I didn't even notice that. But since that was copied and
pasted, I would say that yes, it really does. That's a pretty simple
grammatical bugfix though.

ChrisA
 
J

John Ladasky

Thought this group would appreciate this: www.metabright.com/challenges/python

I have to concur with what several other people are saying here. Several of MetaBright's questions are ambiguously worded, or expect non-idiomatic Python code. It might be helpful for you to ask (hire?) some seasoned Pythonprogrammers to critique your questions.
 
C

Chris Angelico

I have to concur with what several other people are saying here. Severalof MetaBright's questions are ambiguously worded, or expect non-idiomatic Python code. It might be helpful for you to ask (hire?) some seasoned Python programmers to critique your questions.

No need to hire anyone, just posting the questions here will generate
exactly such a critique - as evidenced by this thread :)

ChrisA
 
T

Tim Chase

With tracking cookies blocked, you get 0 points.

And with JavaScript blocked, you get bupkis. :)

I was amused that the sidebar of similar challenges suggested that
the Python challenge might be similar to this one. Ya think? So
similar that even the URL is the same...

-tkc
 
N

Nathaniel Sokoll-Ward

Wow! Thanks for all the feedback everyone. This content is fresh so I appreciate everyone's comments. As opposed to responding to each post individually, I'll just lump everything in here...

Andrew, big thanks for your comments:
"What is the correct number of spaces for indentation in Python?"

I presume the question should be more along the lines of "What does PEP8
say?", because all answers are correct.

I agree. Question has been edited.
"String literals are written with what?"

The answer is not "ALl of these answers are correct"

I believe that string literals can be written with single, double, or triple quotes: http://docs.python.org/release/2.5.2/ref/strings.html
"Which is a correct way to perform exponentiation in Python?"

This was a silly error. Thanks for pointing it out.
What does the following code do?
def a(b, c, d): pass

My answer: "Defines a function which returns None", but that isn't one
of the choices.

Roy, thanks for your note. When I run this code, the function just gets defined and nothing happens. None isn't returned. Do you recall why you found the options available to you unsuitable?
"""How could you open a file c:\scores.dat to write in binary?

outfile = open("c:\\scores.dat", "w")
outfile = open("c:\scores.dat", "a")
outfile = open("c:\\scores.dat", "w")
outfile = open("c:\\scores.dat", "wb")"""

Not technically wrong, but stylistically suspect; I would recommend
using forward slashes (which work fine on Windows) and avoiding the
drive letter, both of which avoid making your example
Windows-specific. (At least, I don't think there are any other
platforms Python supports that use drive letters; OS/2 support was
dropped a little while ago, though I believe Paul Smedley still
maintains a port. But I digress.)

Excellent suggestion. We've gone ahead and made the change.
"""Which method will write a pickled representation of the object to
an open file?"""

Method names without object names aren't all that useful. Do you mean
"Which method of the pickle module..."?

Again, great suggestion.
"""From which languages are Python classes derived from?"""

Sounds like Python history trivia more than a coding challenge, but if
that's what you want to go for, sure.

I agree it's not directly coding related. Our questions are actually sortedinto topic buckets. We try to get a reading on people's knowledge in a bunch of different areas of a given skill. Familiarity with general knowledge facts such as this, gives us another data point to help parse out the typesof questions the best developers tend to get right.
By the way, here's a fairly bad solution to your final question:

array666=lambda x:b"\6\6\6" in bytes(x)

Works for the given test-cases! Doesn't work with arrays at all,
despite the description.

Chris, I actually really like your answer, even if it doesn't satisfy the goal in the question. I'd give it a vote for cleverness!
You know, I didn't even notice that. But since that was copied and
pasted, I would say that yes, it really does. That's a pretty simple
grammatical bugfix though.

Silly error. Fixed.
I have to concur with what several other people are saying here. Severalof MetaBright's questions are > ambiguously worded, or expect non-idiomatic Python code. It might be helpful for you to ask (hire?) > some seasoned Python programmers to critique your questions.

Thanks for the thoughts, John. I'd be lying if I said I wasn't disappointedwith how many errors everyone here is picking out. Some of our Challenges are built exclusively by our users, others are built by someone who helped build MetaBright, while others, like the Python Challenge, are built with the help of contractors. Even so, the responsibility to make sure we are publishing high quality content falls on our shoulders and I regret we didn't go a better job of vetting this material.
With tracking cookies blocked, you get 0 points.
And with JavaScript blocked, you get bupkis. :)

I know that's frustrating. Our tech lead will be on here later today to explain why we do this.

Thanks again everyone!
 
M

Mark Lawrence

Roy, thanks for your note. When I run this code, the function just gets defined and nothing happens. None isn't returned. Do you recall why you found the options available to you unsuitable?
<class 'NoneType'>
 
J

jskirst

We do not currently support cookieless or javascript-less browsing. We are definitely looking at relying less and less on cookies, but it's unlikely we'll ever be able to pull out javascript as it limits interactivity too much. Its definitely possible to do, and maybe something we can look at in thefuture, but right now we don't have the resources for that. Sorry for the inconvenience!

- Jonathan Kirst
Lead Engineer at MetaBright
 
T

Tim Chase

it's unlikely we'll ever be able to pull out javascript as it
limits interactivity too much.

It was mostly in jest as it's one of the things I test when doing
web development. That said, the quizzes are mostly just HTML forms
where you pick the answer with a radio button and click the [next]
button. There's not much interactivity there that hasn't been around
since the dawn of the web.

Additionally, I noticed that if I accidentally select an answer
(laptop track-pads aren't the most precise pointing devices), there
was no readily-apparent way to change/fix it before hitting [next].

-tkc
 
C

Chris Angelico

Wow! Thanks for all the feedback everyone. This content is fresh so I appreciate everyone's comments. As opposed to responding to each post individually, I'll just lump everything in here...

Best way, I think :)
I believe that string literals can be written with single, double, or triple quotes: http://docs.python.org/release/2.5.2/ref/strings.html

Hmm. As a general rule, can you consider aiming your quiz - and any
citations like this - at a current version of Python? I'd prefer to
see this sort of thing aimed at the 3.3 docs, though if you want to
cite 2.7 that would also be of value. But 2.5 is now quite old, and
I'd rather not get the impression that you're writing a quiz based on
an unsupported version of Python. :) Though in this particular
instance it makes no difference.
Chris, I actually really like your answer, even if it doesn't satisfy the goal in the question. I'd give it a vote for cleverness!

Heh. Do you know what the limitation of my solution is, though? As I
said, it works for the given test-cases; what sort of input will it
fail on? (And also: What's its algorithmic complexity, and what's the
complexity of a better solution?) That's why I said it's a bad
solution :)

The side comment about arrays, though: Python *does* have arrays, but
they're a different beast from what you're working with, which are
called lists. The version I posted will actually work with any
iterable, but specifying that it be a list might open up some other
options.

BTW, you're going to see a lot of criticism on the list, because
that's the natural state of things. Doesn't mean we didn't enjoy
taking the quiz. :)

In your Intermediate section:
"""Which of the following is false regarding the raw_input() and
input() built-in functions in Python?

The old raw_input() has been renamed to input() in Python 3.x
input() is equivalent to exec(raw_input())
In Python 2.x, raw_input() returns a string.
raw_input() does not exist in Python 3.x"""

Technically one of those is false, but (a) you really need to specify
versions a LOT more clearly here, and (b) the falseness is a minor
technicality; it took me a while to notice that you'd written exec
where it actually uses eval. Is that distinction really worth
highlighting in the quiz?

"""Which of the following statements is false?

Python can be used to generate dynamic web pages.
Python can be used for web development.
Python's syntax is much like PHP.
Python can run on any type of platform."""

What does *any type* of platform mean? Do you mean "any platform", and
if so, do you mean that there is no pocket calculator on which Python
doesn't run? Or is there some other "type" of platform?
<class 'module'>

I get it. Python will run on any module. *dives for cover*

BTW, here's my chosen "bad solution" for the boss question at the end
of the intermediate section. I'm sure someone here can come up with a
worse one. Wasn't sure what should be done if all three numbers are
the same, incidentally.

def indie_three(*numbers):
seen = {}
tot = 0
for n in numbers:
seen.setdefault(n, 5)
seen[n] -= 4
tot += n * seen[n]
return tot

Note how I've generalized it to any number of input values AND to any
possible number of duplicates!

ChrisA
 
8

88888 Dihedral

We do not currently support cookieless or javascript-less browsing. We are definitely looking at relying less and less on cookies, but it's unlikelywe'll ever be able to pull out javascript as it limits interactivity too much. Its definitely possible to do, and maybe something we can look at in the future, but right now we don't have the resources for that. Sorry for the inconvenience!



- Jonathan Kirst

Lead Engineer at MetaBright

That is easy. Please use FireFox
plus NoScript to achieve what you
want.
 
R

Roy Smith

Alister said:
your sites answer is " defines a function that does nothing"
once you have defined the function try print (a(1,2,3))
you will see that is does indeed return none, as do all functions without
an explicit return.

Well, if you want to be truly pedantic about it (*), this defines a
function without an explicit return and which does not return None:

def foo():
raise Exception

and, for that matter:

def bar():
import os
os._exit(0) # Or variations, such as exec()

(*) and I do.
 
A

alex23

Well, if you want to be truly pedantic about it (*), this defines a
function without an explicit return and which does not return None:

def foo():
raise Exception


In [2]: import dis
In [3]: dis.dis(foo)
2 0 LOAD_GLOBAL 0 (Exception)
3 RAISE_VARARGS 1
6 LOAD_CONST 0 (None)
9 RETURN_VALUE

Seeing as we're being pedantic, the function *does* return None, it's
just that the return value is never seen because an exception is raise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,729
Latest member
ScarlettJe

Latest Threads

Top