Exercise 1: Write a python program that reads from a text file whose name is provided by the user and including lines relating to the dimensions of three kinds of shapes: Circle, Triangle, Trapezoid...


Exercise 1:<br>Write a python program that reads from a text file whose name is provided by the user and<br>including lines relating to the dimensions of three kinds of shapes: Circle, Triangle, Trapezoid<br>(see figure below for a sample input file). For each shape compute and display its area:<br>- Triangle area = base X height.<br>- Circle area =n radius².<br>- Trapezoid area = (base 1 + base,)X height.<br>Your program should consider the following erroneous cases:<br>• The file does not open/exist<br>• The format of the data in the file is incorrect (e.g. shape name = 'Polygon’), the shape's<br>dimensions are incorrect (e.g. negative value or number of values for a trapezoid not<br>equal to 3: base,, base, and height, or), in which case RuntimeError exception should<br>be raised and the processing should continue.<br>Triangle:<br>50<br>48<br>Shape<br>Area<br>Circle: -10<br>Triangle<br>Circle<br>Trapezoid: 10 12 70<br>1200.00<br>>> invalid dimension<br>770.00<br>Trapezoid: 9<br>32<br>Trapezoid<br>Trapezoid<br>>> missing data.<br>Sample input file<br>Sample output<br>

Extracted text: Exercise 1: Write a python program that reads from a text file whose name is provided by the user and including lines relating to the dimensions of three kinds of shapes: Circle, Triangle, Trapezoid (see figure below for a sample input file). For each shape compute and display its area: - Triangle area = base X height. - Circle area =n radius². - Trapezoid area = (base 1 + base,)X height. Your program should consider the following erroneous cases: • The file does not open/exist • The format of the data in the file is incorrect (e.g. shape name = 'Polygon’), the shape's dimensions are incorrect (e.g. negative value or number of values for a trapezoid not equal to 3: base,, base, and height, or), in which case RuntimeError exception should be raised and the processing should continue. Triangle: 50 48 Shape Area Circle: -10 Triangle Circle Trapezoid: 10 12 70 1200.00 >> invalid dimension 770.00 Trapezoid: 9 32 Trapezoid Trapezoid >> missing data. Sample input file Sample output

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here