Add these to this python program: if there is •Wrong shape •Non-numeric Value •0 or negative number entered for dimension(s)
Add these to this python program:
if there is
'''
//Python program to calculate the area of a circle, triangle, or rectangle
'''
import math
#step one, eneter shape demensions
shape = input("Enter shape (circle, rectangle, or triangle) that the area will be calculated for: ")
A = 0
#step 2. Eneter dimensions needed for shape
if shape == 'circle':
#cicle - radius
radius = float(input('Enter radius: '))
#Cacluate Area - Circle
A = math.pi * radius ** 2
elif shape == 'rectangle':
#rectangle - lengtj and width
length = float(input('Enter lenght: '))
width = float(input('Enter width: '))
#Calculate Area - Rectangle
A = length * width
elif shape == 'triangle':
#triangle - base and height
base = float(input('Enter base: '))
height = float(input('Enter height: '))
#Calculate Area - Triangle
A = base * height / 2
else:
print('You have entered an invalid response')
print('Area =', A)
Step by step
Solved in 2 steps with 4 images