Essential Phone Screen Python Interview Question

The fact is that there are far too many developers with allegedly extensive Python programming experience and education on their resumes who are terrible at some of the most primitive Python interview programming skills.

These days, for our Python Software Developer positions, we now routinely ask during phone screening the following

To prepare for our interview please implement the following code:

For each integer in the range 1 to 100 (inclusive)
Print a line such that:
If it is evenly divisible by 3  print "Fizz"
If it is evenly divisible by 5  print "Buzz"
If it is evenly divisible by 15 print "FizzBuzz"
Otherwise: print the number itself.

Be prepared to talk about testing methodology, refactoring, code maintenance or design considerations

We have done this about a hundred times over the last couple of years. So far no one has gotten a perfect score on it and only one developer has gotten a correct bit of code on the first attempt.

Here's a working solution:

for i in range(1,101):
 if i % 15 == 0:
       print 'FizzBuzz'
 elif i % 5 == 0:
       print 'Buzz'
 elif i % 3 == 0:
       print 'Fizz'
 else:
       print i

That's by no means perfect. But it exactly implements the specified functionality. Less than one in ten people who have been scheduled for phone screening as developers does this well at this problem.

Python Phone Interview Questions

A couple of weeks ago I did a written homework assignment with some essential Python interview questions. During the phone interview discussion after turning in the project, the lead Python Developer couldn't find anything to nitpick and even confessed me he thought I was a better Python Developer than him. The conversation went very well and I felt confident I would be invited to in person interview. You may already guess would happened next. I never heard from them again and all of my attempts at communication were ignored. I'd like to say this was an isolated incident, but that would be a complete lie. I just spent last weekend doing another Python homework assignment and I haven’t heard back from them yet.

Python Phone Interview Questions

Not every developer has the luxury of that much free time to focus on puzzle type Python interview questions just to get a foot in the door. All companies want you coding, sometimes over the phone, sometimes on a computer, sometimes on a white board. The companies take that too far and I am 100% positive that the daily job for people who work there does not involve reversing a string in place or writing a function that determines if a word is a palindrome or not, but those interview questions are meant to shrink the pool of potential hires from the thousands to the dozens. Nobody wants to waste time through a normal interview process with thousands of people, better to stump most of them with idiotic, useless quiz questions and interview only a few dozen developers in person. I get it.

Python Virtual Environment as an interview question

For the last few weeks I have been interviewing several people for Python developer position and to my surprise found out that all of them had no idea about Python virtual environments. Answering this common Python interview question may not get the job, but at least you would continue the interview process.

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project A depends on version Django 1.8 but, Project B needs Django 1.9.6” dilemma, and keeps your global site-packages directory clean and manageable.

$ pip install virtualenv

My disappointment is compounded when a candidate misses this topic even when they claim several years of Python experience. Isolation and repeatable clean environment development without hidden dependencies on the base system is a good thing. Virtual Environment primary goal is to conveniently provide Python level isolation. For Python packages that depend on system libraries, only the Python level part of those packages are isolated. Provided the
developer is fully conscious that this is python-level-only isolation, then it is useful.


I can sense some developers bristle at the mention of virtual environment. What about using Docker instead of virtual environment? You can install all dependencies inside a container instead of virtualenv. Installing dependencies in Docker has it's advantages over using just virtual environment, because thanks to containers, the developer doesn't have to worry about system's dependencies, and your app is now better isolated. However running Python becomes a bit cumbersome, because developer doesn't have dependencies installed on machine, and developer would have to get into docker container to run Python there. Just use Python as you always do

Python Essential Interview Questions

One of the most essential Python interview questions is explaining to interviewer the reason for having __main__() function in Python

if __name__ == "__main__":
main()

Python does not have a well defined entry point like Java or C++, it simply executes a source file line by line. In Python, execution of code does not have to start at main. The first line of executable code is executed first. Every module has a name and statements in a module can find out the name of its module. This is partuculary useful in one particular situation, as mentioned before, when a module is imported for the first time, the main block in that module is executed. What if we want to execute the block only if the program was used by itself and not when it was imported from another module? This can be achieved using the name attribute of the module

ImportError: No module named - SOLVED

Before software developer goes in for a Python interview, there are a few things which one should refresh. For example how about solving "ImportError: No module named requests" error.

Imagine that the Python interpreter returns this error on basic "import requests" command

➜ ~ python
Python 2.7.11 (default, Jan 15 2016, 21:24:19)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "", line 1, in 
ImportError: No module named requests

The most obvious check is to run Python's package manager - pip to show details about an installed package. If it returns nothing, it means that package is not installed.

➜ ~ pip show requests
➜  ~

One more precise check is to execute the same pip to list installed packages

➜ ~ pip list
pbr (1.8.1)
pip (8.1.1)
setuptools (20.2.2)
six (1.10.0)
stevedore (1.12.0)
virtualenv (15.0.0)
virtualenv-clone (0.2.6)
virtualenvwrapper (4.7.1)
wheel (0.29.0)

The usual trick to answer this Python interview question is to install the request package by running the simple command and than check the installation again.

➜ ~ pip install requests