Skip to content

Instantly share code, notes, and snippets.

@ardasevinc
Created August 11, 2018 15:27
Show Gist options
  • Save ardasevinc/2f0caa3b3b2c54e58ae125d125b4adcf to your computer and use it in GitHub Desktop.
Save ardasevinc/2f0caa3b3b2c54e58ae125d125b4adcf to your computer and use it in GitHub Desktop.
Area calculator v2
##Area Calculator Version 2
import math
import sys
import time
def area_rect(x,y):
rect=x*y
return rect
def area_square(x):
sq=x**2
return sq
def area_tri(x,y):
tri=(x*y)/2
return tri
def area_sphere(x):
sp=4*(math.pi)*(x**2)
return sp
def area_circle(x):
circ=(math.pi)*(x**2)
return circ
print("Welcome to the area calculator")
time.sleep(1)
print("This little program only calculates the areas of rectangle, square,triangle, sphere and circle")
time.sleep(1)
usr_input= str.lower(input("Please enter the object's name: "))
if usr_input=="rectangle":
x= float(input("Please enter a side's length of your rectangle: "))
y= float(input("Please enter the other side's length: "))
print("Area of your object is:",area_rect(x,y))
time.sleep(2)
print("Thank you.")
elif usr_input=="square":
x= float(input("Please enter a side's lenght of your square: "))
print("Here's the area: ",area_square(x))
time.sleep(2)
print("Thanks for your time.")
elif usr_input=="triangle":
x= float(input("Please enter the triangle's height: "))
y= float(input("Please enter the triangle's side length: "))
print("Here's the area you wanted: ",area_tri(x,y))
time.sleep(2)
print("Goodbye")
elif usr_input=="sphere":
x= float(input("Please enter the radius: "))
print("Here you go: ",area_sphere(x))
time.sleep(2)
print("Say cheese")
elif usr_input=="circle":
x= float(input("Please enter the radius of your circle: "))
print("Here is the area: ",area_circle(x))
time.sleep(2)
print("See you again")
else:
print("I don't do that")
time.sleep(1)
print("END")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment