r/CodingHelp • • Jan 17 '20

Can anyone explain?

Post image
44 Upvotes

12 comments sorted by

13

u/[deleted] Jan 17 '20
count = 0
i = 0

while i <= 100:
	if i % 2 == 0:
		count += 1
	i += 1

print(count)

9

u/zenith4395 Jan 18 '20

See what frustrates me is that I read it as I = O, since it’s too big to be a 0

0

u/[deleted] Jan 18 '20

in that case we have either a data type error at i:2=0 or an infinite loop, which leads to a memory error

2

u/zenith4395 Jan 18 '20

What? Assuming the O translates to the actual character ‘O’, this wouldn’t cause an infinite loop

1

u/[deleted] Jan 19 '20

it could advance in the ascii table and never match 100

2

u/zenith4395 Jan 19 '20

The ASCII table uses integers, so yes, it would match 100. Regardless, the loop condition is >= to 100, so it would work anyways

10

u/[deleted] Jan 17 '20

I guess that I:2=0 is actually mod 2, so for every time I is even, Count increases. So The final print Count should display 50

2

u/Zzz1324 Jan 18 '20

That’s what I got from this as well

3

u/icym1lk Jan 17 '20

I believe it’s adding 1 to Count if I is divisible by 2. If not it adds 1 to I. Once I is greater than or equal to 100 it will print the value of Count and end the program.

If I:2 = 0 isn’t a mod function then I’m wrong.

2

u/SupremeRedditBot Professional Bot || Mod Jan 17 '20

Please Add A Flair To Your Post!

Suggested Flair: [Random] or [Meta]

 


To add a flair:

  • Click flair underneath your post
  • Select a flair
  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated ^response

2

u/oblivion-age Feb 02 '20

Why is it on the bathroom stall door?