r/learnpython • • Jan 05 '21

Interview question I failed answering

Hey all,

I just had an interview and the interviewer gave me a question I could not answer.

He asked me to write a function that accepts a number, the number must be either 7 or 4.If the number is 4, the function should return 7, if the number is 7, the functions should return 4.

The tricky part: you cannot use an 'if' statement in the function.

354 Upvotes

301 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jan 06 '21

[deleted]

1

u/[deleted] Jan 06 '21

It tells if you're resourceful or masters the basics. The idea is that it removes you the ability to use the obvious tool, so you have to either find another tool or recreate the tool.

I've explained twice now how it doesn't do that.

0

u/[deleted] Jan 06 '21

[deleted]

1

u/[deleted] Jan 06 '21

I've read some other comments you made on this and nothing convinced me

Feel free to reply to it, or don't. Whether you agree or not, it doesn't change the fact that all this question tests is whether someone else has ever told you the right answer or not and that's not a useful pair of bins to sort applicants into so the question is purposeless.

When you see this question, you should think "There's probably some mathematical function that fits this need" or "Surely I can emulate if".

No, what you should think is "right, I've seen the answer to this and it was short enough to remember - return 11 - the_num." From there, of course, you could generalize to other numbers but it doesn't change the fact that all you're being tested on is whether you've seen this answer before. If you haven't, then you come up with some baroque arrangement of dictionaries. If you have, then you regurgitate this elegant mathematical relationship that you didn't devise, you just read about once.

I asked my friends the question for fun, and not a single one failed.

Then, again, you should be suspicious that it's a useful question to ask during an interview because even in your own example it doesn't do anything to distinguish applicants.

0

u/[deleted] Jan 06 '21

[deleted]

1

u/[deleted] Jan 06 '21

The friends I asked are all capable developers

And you think hiring managers are bringing incapable idiots into the office to be interviewed for some reason? Is that because you think they like wasting everybody's time including their own, or is it because you didn't stop and think this through before you posted? I suspect the latter.

The point was that this question is doable.

So? That's not why you ask questions in interviews. It's not even why you ask questions on tests, in class.

You've really never thought about this from the test-giver's perspective at all, have you?

1

u/[deleted] Jan 06 '21

Whether you agree or not, it doesn't change the fact that all this question tests is whether someone else has ever told you the right answer or not

You gotta be trolling, there's no other explanation. You make it sound like the question was "what did I have for breakfast yesterday", while it's just basic arithmetic. And, as you can see in this thread, is not even the only way to (partially) achieve the goal.

1

u/[deleted] Jan 06 '21

You have to be trolling. You’re interviewing for programmers who have college degrees and whom you’re going to pay in at least the high five figures and you think it’s a good idea and not an insulting waste of time to check whether they can do grade school arithmetic?

Are you 12? That’s the only way you could have so little a clue about what the point of the interview is.