Created
April 29, 2017 11:00
-
-
Save odanga94/3c5e08632ac5fe17b54f4a031ec7c2e8 to your computer and use it in GitHub Desktop.
Code Academy python lesson: Area Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This program prompts the user to select either a circle or a triangle and returns the area of that shape""" | |
from math import pi | |
from time import sleep | |
from datetime import * | |
now = datetime.now() | |
print "Welcome to Calculator 1.0" | |
print "%s/%s/%s %s:%s" %(now.month, now.day, now.year, now.hour, now.minute) | |
sleep(1) | |
hint = "Don't forget to include the correct units! \nExiting..." | |
option = raw_input("Enter C for Circle or T for Triangle:") | |
option = option.upper() | |
if option == "C": | |
radius = float(input("Enter the radius:")) | |
area = pi * (radius**2) | |
print "The pie is baking..." | |
sleep(1) | |
print "%.2f \n%s" % (area, hint) | |
elif option == "T": | |
base = float(input("Enter the base of the triangle:")) | |
height = float(input("Enter the height of the triangle:")) | |
area = 0.5 * base * height | |
print "Uni Bi Tri..." | |
sleep(1) | |
print "%.2f \n%s" % (area, hint) | |
else: | |
print "You entered garbage and the program will exit" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment