Generating unique, ordered Pythagorean triplets

前端 未结 19 1279
借酒劲吻你
借酒劲吻你 2020-11-29 16:57

This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can

19条回答
  •  死守一世寂寞
    2020-11-29 17:47

    Yes, there is.

    Okay, now you'll want to know why. Why not just constrain it so that z > y? Try

    for z in range (y+1, 1000)
    

提交回复
热议问题