Use files( handling exception) Circle area = n radius?.> Trapezoid area =(base 1 + base2)X height.2Your program should consider the following erroneous cases:The file does not open/existThe...


Use files( handling exception)


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>O Triangle area =<br>2<br>- base X height.<br>> Circle area = n radius?.<br>> Trapezoid area =<br>(base 1 + base2)X height.<br>2<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: basei, base2 and height, or), in which case RuntimeError exception should<br>be raised and the processing should continue.<br>Shape<br>Area<br>Triangle:<br>Circle: -10<br>50<br>48<br>Trapezoid: 10 12 70<br>Trapezoid:<br>Triangle<br>Circle<br>1200.00<br>9 32<br>>> invalid dimension<br>Trapezoid<br>Trapezoid<br>770.00<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: O Triangle area = 2 - base X height. > Circle area = n radius?. > Trapezoid area = (base 1 + base2)X height. 2 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: basei, base2 and height, or), in which case RuntimeError exception should be raised and the processing should continue. Shape Area Triangle: Circle: -10 50 48 Trapezoid: 10 12 70 Trapezoid: Triangle Circle 1200.00 9 32 >> invalid dimension Trapezoid Trapezoid 770.00 >> 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