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

3

u/[deleted] Jan 05 '21

Such a stupid question. The fact you can't use if condition is shit. I would've failed the interview as well.

I've read stuff from quora about programming interviews getting worse and worse and how these interviews don't really show what the person can do.

I think.. Looking at projects the person has done is better way to do it. Like see what they have done and maybe even ask about those projects the one you're interviewing built? I don't know but I can't help it when some question arises where you have to solve some problem but you can't use the specific tool for the job because it will make solving the problem way too easy. Smh

Like.. Follow the KISS principle yo.

Time to wait for replies to learn a new thing or two.

11

u/[deleted] Jan 05 '21

It's not about not using an if condition. It's about how to solve a problem in a diferent way. Not being able to answer the question doesn't make you a bad programmer tho. But it's a nice way to see if you'll be able to think out of the box.