PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def sums(num):
"""
takes the number sent from main and prints an ordered list of all numbers less than that which are the sum of 2 squares.
"""
sum=0
for i in range(num):
for root1 in range(i+1):
square1=root1**2
for root2 in range(i+1):
square2=root2**2
sum=square1+square2
if sum==i:
print(str(root1) + "^2 + " + str(root2) + "^2 = " + str(i))
break
if sum==i:
break
def main():
"""
takes input and calls sums function.
"""
num=int(input("I want numbers less than "))
print(str(num) + " that are the sum of 2 squares.\n")
sums(num)
main()
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run