0

How do I take out duplucates from an array in pairs of two?

I am trying to display output in root instead of float import math a = float(input("Insert a: ")) b = float(input("Insert b: ")) c = float(input("Insert c: ")) ar = int(a) br = int(b) cr = int(c) s =(a + b + c) / 2 sr = int(c) ans = math.sqrt(s * (s - a) * (s - b) * (s - c)) ansr = [] while ans <= 0: if ans % 2 == 0: ansr.insert(len(ans),2) ans /= 2 elif ans % 3 == 0: ansr.insert(len(ans),3) ans /= 3 elif ans % 7 == 0: ansr.append(len(ans),7) ans /= 7 currently upto 7 as that is what most square roots have my plan is to remove every two pairs of commons, and multiply the remaining array

13th Sep 2020, 8:05 AM
Sourav Parik
3 ответов
+ 4
Hi Sourav Parik I've had a look through your codes and I have a number of questions. 1) s = (a + b + c) / 2 - are you trying to find an average here? If so, then divide by 3, not 2. 2) sr = int(c) - should this be int(s)? 3) ans = math.sqrt... - ans will almost certainly be a non-integer. This will mean that none of your ifs (if ans % 2 == 0, etc.) will return True, so they won't be executed. 4) What is this algorithm you are trying to implement? 5) What do you mean by display output in root instead of float? To make things much easier for us and for you, please paste your code into SL's code playground, save it, and then paste the link here 👍
13th Sep 2020, 8:51 AM
Russ
Russ - avatar
+ 2
I see. There is no inbuilt way to display a number as a root as far as I'm aware. The only way I can think of to do this would be to try to divide the number by square numbers until you can't any more, and manually output the number in the desired format. I'll show my quick attempt at doing this... https://code.sololearn.com/c0DEn14BOokG/?ref=app
13th Sep 2020, 9:14 AM
Russ
Russ - avatar
0
Russ, By that I mean x(root symbol)y instead of decimal points, I am trying to make heron's formula, s = semi perimeter and ar/br/cr/sr is a scrapped idea that I forgot to take out oh and yeah I forgot about that, could it work by converting to int or is there a different method?
13th Sep 2020, 8:56 AM
Sourav Parik