Question

In: Computer Science

Right Triangle:If the square of one side equals the sum of the squares of the other...

Right Triangle:If the square of one side equals the sum of the squares of the other
two sides. in python

Solutions

Expert Solution

To check if the given triangle is right angled or not, we have to first identify the longest side. Once it is identified we can consider it as the LHS of the pythogaras equation. The sum of the square of the other 2 sides are then considered as RHS. Both LHS and RHS are comapred to check whether the given triangle is right angled.

Code:

import math

# Calculate the right side of the pythogaras equation
def rightsidecal(hypo, side1, side2, side3):
  if hypo == int(side3): # If side3 is the hypotenuse
    rightcal = (math.pow(int(side1), 2) + math.pow(int(side2), 2))
    return rightcal    
  elif hypo == int(side2): # If side2 is the hypotenuse
    rightcal = (math.pow(int(side1), 2) + math.pow(int(side3), 2))
    return rightcal
  elif hypo == int(side1): # If side1 is the hypotenuse
    rightcal = (math.pow(int(side2), 2) + math.pow(int(side3), 2))
    return rightcal
  
# Compare the lhs and rhs of the pythogaras equation and output if the triangle is right angled or not
def comp(lhs, rhs):
  if lhs == rhs:
    print("Right Angled Triangle")
  else:
    print("Triangle is not Right Angled")

def main():
  side1, side2, side3 = input('Enter the length of sides of the triangle (Space seperated): ').split() # Input the length of 3 sides of the triangle
  hypo = int(max(side1, side2, side3)) # Hypotensue is the longest side of a right angle triangle
  lhs = math.pow(hypo, 2) # Square of the hypotenuse
  rhs = rightsidecal(hypo, side1, side2, side3)
  comp(lhs, rhs)

main()

Output:


Related Solutions

1)With​ two-way ANOVA, the total sum of squares is portioned in the sum of squares for​...
1)With​ two-way ANOVA, the total sum of squares is portioned in the sum of squares for​ _______. 2) A​ _______ represents the number of data values assigned to each cell in a​ two-way ANOVA table. a)cell b) Block c)replication D)level 3.) True or false: In a​ two-way ANOVA​ procedure, the results of the hypothesis test for Factor A and Factor B are only reliable when the hypothesis test for the interaction of Factors A and B is statistically insignificant. 4.)Randomized...
ANOVA Essay Mark (%)   Sum of Squares df Mean Square F Sig. Between Groups 1619.229 3...
ANOVA Essay Mark (%)   Sum of Squares df Mean Square F Sig. Between Groups 1619.229 3 539.743 56.767 .000 Within Groups 389.831 41 9.508 Total 2009.060 44 Next, in your own words write out a one-tail hypothesis regarding your One-Way ANOVA model. The one tail hypothesis is that there is a significant difference in mean scores between Essay mark and grade level. The null hypothesis hypothesis is that there is no significant difference between the essay mark and grade level....
If the sum of the debit column equals the sum of the credit column in a...
If the sum of the debit column equals the sum of the credit column in a trial balance, it indicates: Select one: a. no errors can be discovered. b. that all accounts reflect correct balances. c. the mathematical equality of the accounting equation. d. no errors have been made.
Along, square, electrical heating element standing on a corner with one side of the square heating...
Along, square, electrical heating element standing on a corner with one side of the square heating element being 25mm, thermal conductivity k = 240 W/m ? K, density ñ = 2700 kg/m3, and specific heat cp = 900 J/kg ? K is installed in a duct for which air moves in cross flow over the heater at a temperature and velocity of 30°C and 10 m/s, respectively. (a) Neglecting radiation, estimate the steady-state surface temperature when, per unit length of...
1) Aris uses a boat to cross from one side to the other side of a...
1) Aris uses a boat to cross from one side to the other side of a river of width w = 32 m. The river flows at VC = 8 m/min. and he can row at a speed of VB =30 m/min. in still water. He wants to land at a dock which is L=10 m downstream from a point directly opposite his starting point. a) In what direction (i.e. angle relative to the bank), should he aim his boat...
Given a square of side a, lying in the x-y plane, with one corner at the...
Given a square of side a, lying in the x-y plane, with one corner at the origin and the two adjacent sides aligned with the x and y axis, respectively. Three of the corners of the square are occupied by fixed charges: two equal positive charges Q each at (a,0) and (0.a), and a negative charge -q at (a,a). There is NO charge at the origin (0.0). We want to find and discuss the NET electric field AT THE ORIGIN...
A square with side lengths 5 centimeters is positioned with one apex at the center of
A square with side lengths 5 centimetres is positioned with one apex at the centre of a second square (which has side lengths of 4 centimetres). The longest side of the overlapping (shaded) quadrilateral region has a length of 3 centimetres. Calculate the area of the shaded region. Show your full working-out together with an appropriately labelled sketch.  
There are at most two squares (not necessarily with the same size) such that the sum...
There are at most two squares (not necessarily with the same size) such that the sum of the area(s) is 8 in^2 . Maximize and minimize the sum of the perimeter(s)?
1. The right side of a T-account is used to record Select one: a. Decrease in...
1. The right side of a T-account is used to record Select one: a. Decrease in revenue b. Increase in Asset c. Decrease in liability d. Increase in Liability 2. Odd-man Out. Choose the letter that does not belong to the group. Select one: a. Interest Income b. NSF check c. Notes Receivable collected by banks in behalf of the depositor d. Proceeds of bank loan deposited in the account of the depositor 3, Any retiring partner may do any...
What is a dummy variable? If we use one on the right-hand side of the equation...
What is a dummy variable? If we use one on the right-hand side of the equation in a multivariate analysis, what are the implications for interpreting the constant?  What is multicollinearity? How do we know if we have it in our models? How do we correct for it if we do?  What is hetereskedasticity? Should we really be concerned about it? Why or why not?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT