Using type() in my calculator



Hey folks, so for a fun project to test my knowledge thusfar I've created a basic area calculator, and I wanted to add something that noted if the user inserted something other than a numerical value for the height or width etc of the shapes, however when I use the type() I get issues!

I'm pretty confused here as to why this isn't working and would appreciate any help y'all could offer!

from datetime import datetime
from time import sleep
import os
import sys
import psutil
import logging
import math

now =
print "This is an area calculator!"
print "We're booting up the ole brain!"
sleep (1)
print "..." 
sleep (1) 
print "..." 
sleep (1)   
print "... the current time is %s:%s \n\n" % (now.hour, now.minute)

shape = raw_input("Please type a shape:")
shape = shape.lower()
#Square area 
if shape == "square" and shape.isalpha():
    n = int(raw_input("Please type a number:"))
    sqr = n ** 2
    print "The area of your SQUARE is %s" % (sqr)
    if type(n) != int:
        print "Please type a NUMBER." 
#Rectangle area
elif shape == "rectangle" and shape.isalpha():
    l = int(raw_input("Please insert the length:"))
    w = int(raw_input("Please insert the width:"))
    rect_area = l * w
    print "The area of your RECTANGLE is %s!" % (rect_area)
    if type(l, w) != int:
        print "Please type a NUMBER." 
#Triangle area
elif shape == "triangle" or shape == "tri" or shape == "tri-angle" and shape.isalpha():
    base = int(raw_input("Please insert the base:"))
    height = int(raw_input("Please insert the height:"))
    tri_area = 0.5 * base * height
    print "The area of your TRI-ANGLE is %s!" % (tri_area)
    if type(base, height) == int:
        print "Please type a NUMBER." 
#Circle Area
elif shape == "circle" or shape == "cir" and shape.isalpha():
    radius = int(raw_input("Please supply the radius:"))
    circle_area = math.pi * radius ** 2
    print "The area of your circle is %s!" % (circle_area)
    if type(radius) != int:
        print "Please type a NUMBER." 
    print "You don't know what a shape is? Try either square, rectangle, or triangle!"

def restart_program():
    """Restarts the current program, with file objects and descriptors

        p = psutil.Process(os.getpid())
    except Exception, e:

    python = sys.executable
    os.execl(python, python, *sys.argv)
print "Try another shape!"
sleep (1)
print "Restarting calculator..."
sleep (2)


Have you considered using a combination of something like try/except and a while loop? Something like that? (You would wrap input() with int() and catch the exception).


no, I haven't even gotten to those terms as vocabulary in the codeacademy. I'm at Python Lists and Dictionaries "The next part is key" to be exact.