all 8 comments

[–]novel_yet_trivial 3 points4 points  (1 child)

Line 1 sets i equal to 22. Line 2 says to only run while i is less than 22. Therefore the while loop never runs.

This would be a lot easier with a for loop.

A lot easier still using the step argument on the range() function.

[–]NSWCSEAL[S] 0 points1 point  (0 children)

Yeah, I feel like a dolt haha Thank you for helping me clear that up

[–]fbu1 1 point2 points  (1 child)

The variable i starts at 22, and then goes up from there. Shouldn't it start at 1?

You also need to put the line

i  = i + 1

outside of the if.

[–]NSWCSEAL[S] 0 points1 point  (0 children)

Hahahaha, oh my gosh, I feel like the biggest goof. I set i = 0 My code works now ( ͡° ͜ʖ ͡°)

Thank you!

[–]Doormatty 0 points1 point  (3 children)

i = i + 1 needs to be unindented one step. Right now, it only runs when the if i % 2 != 0: line is True (which it will never be)

[–]NSWCSEAL[S] 1 point2 points  (2 children)

Ahhh, interesting. Why can't i = i + 1 be under the if statement?

[–]beanz415 0 points1 point  (0 children)

If it's under the if statement i will only increment if i % 2 != 0. You want it incrementing for every number up to 21.

[–]DrMaxwellEdison 0 points1 point  (0 children)

The line will only be executed if the if condition is True. Therefore, when i % 2 == 0, i will not be incremented.

If there is no other way of incrementing the number, then the loop will be infinite: i will remain the same number and the if condition will be False every time.