Solve Math Problem Using Python. HALP PLS

0 Shivam Misra · August 19, 2015
So i was given this math problem:

I am pretty much stumped. So far I have made a very basic code for finding if a number is a square number or not, but I'm not sure how to continue. 
How do I come about this?

Post a Reply


Oldest  Newest  Rating
0 wernich wilsenach · August 20, 2015

i'd go on that exact formula: calculate a2 + b2 , then see if you can get an int from the square root.

start with two variables ("a" and "b" if you like) and then see if the two added together are a perfect square. you could do a nested loop so that you can compare 1 and 1, then 1 and 2, then 1 and 3... upto the max you should check, then check 2 and 1, then 2 and 2, then 2 and 3... and so on. when you get a perfect square for "c", then you print those values out. 

doing it that way should get you the right answers, but you're very likely to get duplicates. get the right answers first, then sort out the duplicates. ;)
0 Otto Von Chesterfield · August 20, 2015
from math import sqrt

def findC(a, b):
return sqrt(a**2 + b**2)
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator