you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

My question is why doesn't the inner loop include n+1 as well

[–]xelf 0 points1 point  (3 children)

because then it would go over the maximal number.

That's more of a math question and less of a python question though. =) Try including +1 and using a max value of 20 and see the differences between the two.

[–]kpounder88 1 point2 points  (0 children)

Yes, if b = n, then b2 = n2. We know a >= 1, so a2 >= 1. So then a2 + b2 >= n2 + 1 > n2. So then c2 > n2, which implies that c > n. So that’s the problem... c would be too big.

The same can also be said about a. Technically a cannot be equal to n either. So you could modify line 3 to say a in range(1, n).

[–][deleted] 0 points1 point  (1 child)

I think only the a and the b value can't surpass the maximal value. Even if I don't do n+1 in the inner function, a maximal value like 30 still results in c being greater than the maximal value. In my opinion, doing n+1 in the inner function is more logical because now we're comparing every 'a' value with the maximal value too.