Base and heigh and radius input with string


#1

This program can compute the area of a given shape. The given shapes are Cicle and Triangle.

from math import pi
from time import sleep
from datetime import datetime

now = datetime.now()

print "the calculator is starting up."

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(raw_input("Enter radius: "))
area = pi * radius**2
print "The pie is baking..."
sleep(1)
print ("area: %.2f. \n%s" % (area, hint))
elif option == 'T':
base = float(raw_input("Enter base: "))
height = float(raw_input("Enter height: "))
area = base*height*(0.5)
print "Uni Bi Tri"
sleep(1)
print ("area: %.2f. \n%s" % (area, hint))
else: print "You have entered garbage.\nExisting..."

I get errors if I enter string in the base and heigh and radius input. How can I code it to tell the users to use only number in the raw_input in base and height and radius?


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.