Feb-13-2017, 05:56 PM
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.
Given a range (again, let's say 15), print a given text that many times, to give the appearance of steps.
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 FizzBuzzIf 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 FizzBuzzPrint 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 SpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamSpamRight. 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.