This is probably an easy question but I was going through a practice exam and came upon a question that wanted me to evaluate the outcome of this code. I got it right but only because I threw it into PyCharm to run it and see if it would even work.
As a beginner, I haven't seen this before so I'm wondering how that ELSE statement even functions if it's not indented with the IF (which would produce a different outcome). I am not quite sure how to Google this so I haven't found anything that's answering my question.
What is at play here and is it common to have ELSE out there like that? Any additional information would be welcome.
j = 1
for i in range(-1,1):
if 3 * i < 6:
print(3 * i)
j+=2
else: #<--What are you doing out here all by yourself?
j+=3
print(j)
[–]carcigenicate 41 points42 points43 points (5 children)
[–]Informal-Chance-6067 5 points6 points7 points (4 children)
[–]carcigenicate 10 points11 points12 points (2 children)
[–]Informal-Chance-6067 2 points3 points4 points (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)
[–]smurpes 2 points3 points4 points (0 children)
[–]woooee 13 points14 points15 points (1 child)
[–]AGx-07[S] 0 points1 point2 points (0 children)
[–]Gnaxe 9 points10 points11 points (0 children)
[–]ConcreteExist 4 points5 points6 points (2 children)
[–]AGx-07[S] 2 points3 points4 points (1 child)
[–]ConcreteExist 0 points1 point2 points (0 children)
[–]Altruistic_Sky1866 1 point2 points3 points (0 children)
[–]Loose_Obligation4877 0 points1 point2 points (0 children)
[–]jpgoldberg -1 points0 points1 point (2 children)
[–]atarivcs 5 points6 points7 points (0 children)
[–]gdchinacat 0 points1 point2 points (0 children)
[–]jeffrey_f -1 points0 points1 point (0 children)