Area Calculator made using Python

1 min read
I made a project in python that calculates the area of a square, circle, rectangle or triangle.
print("WELCOME TO AREA CALCULATOR")
print("YOU CAN CALCULATE AREA OF SQUARE, CIRCLE, RECTANGLE,TRIANGLE")
x=input('which shape?')
if x == 'square':
y=float(input('enter side length:'))
print ("area=",y**2)
elif x == 'circle':
z=float(input('enter radius:'))
print('area=', 3.14*z**2)
elif x=='rectangle':
m=float(input('enter length:'))
n=float(input("enter breadth:"))
print('area=', m*n)
elif x=='triangle':
a=float(input('enter base:'))
b=float(input("enter height:"))
print("area=", 0.5*a*b)
else:
print("sorry, shape not supported")
I recently learned about conditions in python: the if, elif and else statements, so i used them in makng a project. The if statement is like a true/false question. If the thing written next to if is true, then it will execute the code in the block below it, else it will move to elif, which also does the same thing.
If any of the if or elif statements will not be correct, then the else statements block will executed.
I am learning from MITOpenCourseWare and the lectures by Ana Bell mam are great.
Thanks for reading!
1
Subscribe to my newsletter
Read articles from Utkarsh Narayan Tiwari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
