I'm learning python and I want to make sure I am organizing "if" statements in a correct way. The situation that I keep running a lot into is the following :
if x == 0:
dostuff_A
if y == 0:
dostuff_B
else:
dostuff_B
As you can see I keep repeating "dostuff_B" a lot and have to contantly be changing code twice. I know I could have a function instead "dostuff_B" but my question is regarding the if design. Another workaround that I found is doing the following but then i duplicate the if statement.
if x == 0:
dostuff_A
if x != 0 or y == 0:
dostuff_B
Any ideas? Thanks in advance!
UPDATE : Removed spaces before colon. Also updated my workaround because didn't make sense. Original version was :
if x == 0:
dostuff_A
if x == 0 and y == 0:
dostuff_B
:ifshould beif x != 0 or y == 0: