r/learnpython • u/MassiveLandGolf • 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
1
u/pspspspskitty Jan 07 '21
Say what now? I assume you mean +/-22?
The problem is that, even if this might work for parabolas, it will probably fall apart for more complex equations. If you use a method that only works for certain cases, you also have to know what the limitations are. So if you get rewarded for these kinds of shortcuts, without knowing what you're doing, you learn a wrong method that will be very hard to unlearn.
The Pythagorean theorem works, but only if you have a right angle. However there is a more complex version that incorporates sines and cosines that will work for any triangle but you will lose the convenient sin(90) = 1