Python Forum

Full Version: Drop Dead Simple Interview Questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
What's some good interview questions?  There's FizzBuzz, and "print a ladder", what else do you have?

And sure, let's share answers why not.  Since I mentioned two, I'll go through them.

FizzBuzz:
In a given range (let's say 15), print something to the screen.  If the number is divisible by 3, print "Fizz".  If it's divisible by 5, print "Buzz".  If it's divisible by both, "FizzBuzz".  If it's not divisible by either, print the number itself.
>>> for ans in map(lambda n: "FizzBuzz" if 0==n%3 and 0==n%5 else "Fizz" if 0==n%3 else "Buzz" if 0==n%5 else n, range(1, 16)):
...     print(ans)
...
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
If you actually want the job, then this would be better (or having four print statements, and using "end=''" a lot):
>>> for n in range(1, 16):
...     ans = ""
...     if 0 == n%3:
...         ans += "Fizz"
...     if 0 == n%5:
...         ans += "Buzz"
...     if not ans:
...         ans = n
...     print(ans)
...
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
Print a Ladder:
Given a range (again, let's say 15), print a given text that many times, to give the appearance of steps.
>>> def ladder():
...     text = input("What you wanna see? ")
...     return [text*n for n in range(int(input("How many steps? ")))]
...
>>> for step in ladder():
...     print(step)
...
What you wanna see? Spam
How many steps? 15

Spam
SpamSpam
SpamSpamSpam
SpamSpamSpamSpam
SpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam
SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpam
Right.  So the questions should be super easy, and exist for no reason other than to prove the person knows more than just the requisite technology stack lingo to fake it.
Quote:What's some good interview questions?
I like the idea of a thread showing possible or realistic questions asked....but i dont think the thread should be gen coding help. Maybe discussions? Or stickied in jobs? OR maybe tutorials....im not really sure where to put it.
Moved it Wink

Quote:If you actually want the job, then this would be better (or having four print statements, and using "end=''" a lot):
Njaa i could be that interviewer now a little functional programmering,and are happy with map and lambda.
The next question could then be,has it side effects Think
Yeah, I had no idea, so I went general. I was thinking Jobs also, but the description is very specifically for job posters or seekers, not general info about jobs.
Quote:I was thinking Jobs also, but the description is very specifically for job posters or seekers, not general info about jobs.
i personally think it would depend on how many people participate with different ideas, as to where it should go at the end. IF not a lot of people add things, i think it should stay here in discussions.
Simple file reading?  I'm not sure if this is better than csv, or if just seeing the general way people handle resources is more important...

>>> text = '''
... hello, my name is
...     wait, who am i?
... '''
>>> text = text.split('\n')
>>> with open('saved_data.txt', 'w') as f:
...     for line in text:
...         print(line, file=f)
...
>>> text = "spam"
>>> # now we don't have any reference to the original text floating around
...
>>> with open('saved_data.txt') as f:
...     for line in f:
...         print(line.rstrip())
...

hello, my name is
   wait, who am i?

>>>
I never ask job applicants to write a program for me. I ask them to send me a program they've already written. That usually tells me plenty. Unfortunately, it's rarely anything I want to hear.
It may also be his friends code
I feel like writing code, right in front of someone, it a good idea. Even if it's not a real language, and just pseudocode. Gluing together snippets from google can only get you so far.
I wouldn't ever give Fizzbuzz, I'd be afraid of insulting the candidate. Are you interviewing them for a specific role or position? Are they expected to be familiar with computer science?

A warmup question I often give is "write a function which takes in a string and returns true if the string represents a number." The candidate is meant to clarify the requirements, and be able to code it up after. If they write something that just handles non-negative integers, I start providing additional sample cases for negative and floating point numbers. They also often don't accommodate for "-", "." and sometimes even after that, "-.".
Pages: 1 2 3