Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background Consider a triangle with sides of lengths a, b, and c where c is the longest side. We can describe the side and angle

Background

Consider a triangle with sides of lengths a, b, and c where c is the longest side. We can describe the side and angle properties of the triangle using these lengths.

The side properties include:

  • scalene if all three sides have a different length
  • isosceles if two of the sides have the same length
  • equilateral if all three sides have the same length

The Pythagorean Theorem determines the angle properties which include:

  • acute if all angles are acute (<90 degrees) or a**2 + b**2> c**2
  • right if one angle is right (=90 degrees) or a**2 + b**2 = c**2
  • obtuse if one angle is obtuse *(>90 degrees) or a**2 + b**2 < c**2

Note that the sides do not represent a triangle if a + b <= c. Both the side and angle relationships should be none in this case.

Solution

Complete the following program to:

  • prompt for a filename
  • print a heading for the output
  • print a line with the side and triangle properties for each triangle in the file

Example Input

Each line in the file contains 3 numbers separated by spaces that represent the side lengths of the triangle as in the following example. The lengths may be in any order on the line.

5 4 3 4 4 4 

Example Output

The side lengths and properties should align with the column headings as in the following example. The side lengths should be right justified and in the same order as the input file, while the properties should be left justified.

111 222 333 angle side 5 4 3 right scal 4 4 4 acute equi 

Test Data File

There is a single test file, triangles you may use to test your program during development.

3 5 4 3 4 4 3 3 6 4 4 4 2 11 4 6 4 3

Provided Code:

# Triangle Properties # # This program: # * prompts for a filename # * prints a heading for the output # * prints a line with the side and triangle properties for each triangle in the file # # Refer to the above description for definitions of triangles/angles

def side(a, b, c): """ Returns 'scalene', 'isosceles', 'equilateral', or 'none' based on the triangle side relationships given the lengths of the sides. """ # add code to return the correct side relationship

def angle(a, b, c): """ Returns 'acute', 'obtuse', 'right', or 'none' based on the triangle angle relationships given the lengths of the sides where c is the longest side. """ # add code to return the correct angle relationship

def triangle_properties(sides): """ Returns a properly formatted string containing the triangle properties from a list of strings containing the lengths of the sides. """ # Don't change this code that figures out the longest side. abc = [int(sides[0]),int(sides[1]),int(sides[2])] c = max(abc) abc.remove(c) a = abc[0] b = abc[1] # add code to return a properly formatted string that matches the column headings

def column_headings(): """ Return a string containing the column headings. DO NOT CHANGE THIS CODE """ return '111 222 333 angle side'

def triangles(filename): """ Prints column headings and a line containing the properties of each triangle in the file. """ print(column_headings()) # add code to process the file, printing the triangle properties for each line in file

def main(): """ Prompts for filename and processes the file. DO NOT CHANGE THIS CODE """ filename = input('filename? ') triangles(filename)

if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions