Python Forum
Drop Dead Simple Interview Questions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop Dead Simple Interview Questions
#24
(Apr-17-2017, 07:50 PM)volcano63 Wrote:
  • The last if would better be elif

I disagree. That would give extra semantic meaning to the "divisible by 5" check that doesn't exist for the "divisible by 3" check. And extra semantic meaning serves no purpose other than to confuse whoever looks at the code in the future.

If you were to look at the code, without knowing the problem ahead of time, you'd see two options:
a) divisible by 3 and
b) divisible by 5

...except that there's an extra clause tacked on to option b that sort of reads "if it's not divisible by 5, and also if nothing else happened so far, then just use the number". Which makes you stop and wonder why option b is special compared to option a. It wouldn't be immediately obvious that it isn't obvious, it just happens to come last in the loop.
Reply


Messages In This Thread
Drop Dead Simple Interview Questions - by nilamo - Feb-13-2017, 05:56 PM
RE: Drop Dead Simple Interview Questions - by wavic - Feb-13-2017, 09:02 PM
RE: Drop Dead Simple Interview Questions - by nilamo - Apr-17-2017, 08:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pipenv & Requests Author Kenneth Reitz Interview Evrone 1 2,104 Jan-28-2021, 02:16 PM
Last Post: elizabethlvova
Star Flask Creator Armin Ronacher Interview elizabethlvova 1 1,953 Dec-16-2020, 09:10 AM
Last Post: Evrone
  Becoming a Self-Taught Programmer: Cory Althoff Interview Evrone 0 1,913 Dec-16-2020, 08:49 AM
Last Post: Evrone
  PEP 594 -- Removing dead batteries from the standard library ichabod801 3 2,793 May-31-2019, 01:23 PM
Last Post: heiner55
  Best resource to learn and pass interview oryucouk 5 3,125 May-18-2019, 05:19 AM
Last Post: heiner55
  MIT Interview with Guido Larz60+ 3 3,388 Nov-27-2018, 10:45 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020