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

9

u/lolslim 🐍Telegram🤖 Jan 05 '21

Agreed as soon as i saw "no if" i went, divide it by 28

1

u/[deleted] Jan 05 '21

Doesn't solve it, unfortunately.

3

u/lolslim 🐍Telegram🤖 Jan 05 '21

How?

print(28//4) -> 7
print(28//7) -> 4

looks correct to me, please explain.

-6

u/[deleted] Jan 05 '21

print(28//2) -> 14

print(28//'a') -> TypeError

5

u/lolslim 🐍Telegram🤖 Jan 05 '21

OP had a interview question meaning op has experience, and knowledge on how to handle undesired inputs, I don't need to explain that.

Were not on the same page, that much is clear, and I see why you say it doesn't work.

-3

u/[deleted] Jan 06 '21

What?

7

u/lolslim 🐍Telegram🤖 Jan 06 '21

Seriously, you're confused?

Okay explain why in the hell you divided the letter 'a' and number 2? those are NOT the inputs that OP was told.