by Brandon Rhodes
• Home
PyCon Trivia Night, Second Edition
Date: |
16 April 2015 |
Tags: | computing, python |
As was the case
during first year that the conference was in Montréal,
I was invited for PyCon 2015 to lead an evening dinner trivia contest
on the first full conference day.
Wanting to help the audience celebrate
all of the advances that are being made in Python 3,
I skewed my questions heavily in the direction
of the strides that the core developers are taking
with the new version of the language.
Alas!
My focus was not as popular with the audience
as I had hoped.
It turns out that Python 2.7 is still far more popular
than its predecessor,
and many contestants were frustrated
about being asked so many questions and details
about a language hardly anybody used.
So I made a promise to the audience:
if a third trivia dinner happens at PyCon 2016 in Portland,
that I will make it Retro Python Trivia Night
and ask all of the questions about the Python 2 series!
The questions follow,
then the answers are way down at the bottom of the post
so you can try answering on your own
before you scroll down and peek.
Enjoy!
First Round Questions
- To open a URL in the user’s
default browser, you would use
which Standard Library module?
- In Python 3, an integer
with a leading 0 is
now a syntax error.
How do you write the old value
0123 in modern Python 3?
- What does the optional second
argument to sum() do?
- What does the optional final
argument to slice() do?
- For or against?
Is PEP-8 for or against
this code’s formatting?
def complex(real, imag = 0.0):
- For or against?
Is PEP-8 for or against
this code’s formatting?
if (this_is_one_thing
and that_is_another_thing):
do_something()
- Which is NOT a built-in
that was newly added
in Python 3?
ascii()
bytearray()
exec()
- The a[b] operation,
backed by the method __getitem__(),
is supported by both list and dict.
But a list raises IndexError
while a dict raises KeyError.
What is the most specific Python
exception you can catch that covers both
IndexError and KeyError?
- What do the letters gai
stand for in the Standard
Library’s gaierror?
- “A Foolish Consistency
is the (what?) of Little Minds”
Second Round Questions
- Which Standard Library module
does not parse command line arguments
when invoked with the -m option?
- json
- webbrowser
- uu
- The functions in the uuid module
run from uuid1() through what?
(BONUS: Which number is skipped?)
- What does the optional third
argument to getattr() do?
- What does the optional third
argument to pow() do?
- For or against?
Is PEP-8 for or against
this line of code?
- For or against?
Is PEP-8 for or against
this code’s formatting?
def munge(sep: AnyStr = None):
- Which one of these three
is NOT a built-in that was
removed in Python 3?
apply()
compile()
file()
- PEP-8 recommends that lines of code
have, at most, how many characters?
- What does the letter h
stand for in the Standard
Library’s herror?
- Special cases aren’t
special enough to _?
Third Round Questions
- In Python 3.4, which Standard Library
module now parses command line
options if invoked with python -m?
- zlib
- tarfile
- hashlib
- What happens if you run python -m turtle?
- import sys; delattr(sys, 'getrefcount')
What is the result?
- TypeError
- AttributeError
- sys.getrefcount() disappears
- sys.getrefcount() remains
- What does the optional final
argument to property() do?
- For or against?
Is PEP-8 for or against
this line of code?
- When writing English comments,
PEP-8 recommends what?
- Chicago Manual of Style
- The Elements of Style
- Associated Press Stylebook
- Always ending with a period
- In Python 3, which of the
following expressions will throw
an exception (choose all that apply)?
- bytearray(memoryview(bytes()))
- bytes(bytearray(memoryview()))
- memoryview(bytes(bytearray()))
- PEP-8 recommends that lines
with comments or docstrings have,
at most, how many characters?
- In Python 3.3, which
did NOT become a
synonym of OSError?
EnvironmentError WindowsError VMSError
- Namespaces are what?
The Winning Teams
The teams with the highest scores are sorted at the top
— congratulations, everyone!
Trivia Team |
1 |
2 |
3 |
Total |
Import Antigravity |
9 |
11 |
7½ |
27½ |
__dogs__ |
8 |
9 |
5½ |
22½ |
JSON & the kwargonauts |
9 |
9 |
4 |
22 |
Unless You're Dutch |
9 |
7 |
5½ |
21½ |
Team PHP |
8 |
4 |
7 |
19 |
Cache Invalidation |
7 |
8 |
3½ |
18½ |
Accidental Combustion |
7 |
8 |
3½ |
18½ |
Literally LVH |
8 |
6 |
3 |
17 |
Brandon Rhodes's Team |
8 |
5 |
4 |
17 |
Badgers |
7 |
7 |
3 |
17 |
Team Spam, Spam, and Spam |
6 |
6 |
5 |
17 |
The Holy Hand Grenade of Antioch |
8 |
5 |
3½ |
16½ |
The Ran Vossums |
7 |
5 |
4½ |
16½ |
**kwargs |
7 |
5 |
4½ |
16½ |
U+1F40D |
5 |
8 |
3½ |
16½ |
Give Us Free Drinks On The House |
6 |
5 |
3½ |
14½ |
from answers import * |
4 |
6 |
4½ |
14½ |
raise NameError |
4 |
5 |
5½ |
14½ |
Why is the rum always gone? WHY!? |
5 |
2 |
2 |
9 |
Data, the gathering |
— |
3 |
3½ |
6½ |
A dash in the table above indicates a missing answer sheet,
that was either never written
or that did not make it from the team’s table
to my own table up at the front of the venue.
First Round Answers
- webbrowser
- Two possible answers are 83 or 0o123.
- Provide the initial value,
which is also the default returned
if the sequence is empty.
- The final argument to slice() provides the step increment
that will be the difference between successive values
in the returned sequence.
- PEP-8 is against complex(real, imag = 0.0)
because the = attaching a default value to a keyword argument
should not have spaces around it.
- PEP-8 is in favor of extra indentation
to visually distinguish extra lines of an if condition
from the 4-space-indented code that follows.
- bytearray() already exists in Python 2.
- LookupError is the superclass of IndexError and KeyError.
- It means “getaddrinfo() error.”
- “A Foolish Consistency is the Hobgoblin of Little Minds” —
the title of the first major section of PEP-8
after its Introduction.
Second Round Answers
- The json module cannot be invoked as a command.
- The highest numbered UUID function is uuid5(),
and uuid2 is the one which is skipped and does not exist.
- The third argument to getattr(obj, name, x)
is the default returned if not attribute of that name exists.
- The third argument to pow() provides the modulo
that should be applied to the return value.
- PEP-8 is against the formatting of x * x + y * y
because there is no visual hint indicating
that multiplication binds more tightly than addition.
- PEP-8 likes how def munge(sep: AnyStr = None):
puts spaces between the annotation type and the argument’s default
value.
- Python 3 elected not to remove the compile() builtin.
- PEP-8 recommends 79 or 99 characters per line,
depending on how generously one reads it,
so both answers were considered correct for the trivia scoring.
- An herror is a “host error” from the networking code.
- “Special cases aren't special enough to break the rules.”
Third Round Answers
- Python 3 gave a command line interface to the tarfile module.
- A graphical turtle demo starts running,
show the kinds of drawing primitives and patterns it supports.
- c — true to Python’s mutable nature,
there is no law against removing this attribute
or, in general, against removing things from sys.
Run del and the function disappears.
- The final (optional) argument to property()
provides the property’s docstring.
I had always thought it provided the deleter,
but there was another argument after that I hadn’t know about!
- PEP-8 is, amazingly enough —
and the trivia crowd protested out loud when I announced it —
against the formatting of c = (a + b) * (a - b)
because it wants less whitespace around more tightly
binding operations even if parentheses are present.
- PEP-8 recommends that The Elements of Style
guide the English used in Python comments.
- The expression bytes(bytearray(memoryview()))
because memoryview() cannot be called with no arguments —
a memory view must be a view of some other value.
- Comments and docstrings are limited to 72 characters by PEP-8.
- VMSError
- From PEP-20, the Zen of Python:
“Namespaces are one honking great idea -- let's do more of those!”
©2021