Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

my first python program


ghost's Avatar
0 0

hi every 1 this is my first python program (for calculating areas) and was hoping could get some feedback on it and if theres a better way of doing what i did

import math
while quit != "yes":
    c = c + 1
    
    shape = raw_input("is it a circle rectangle or triangle?")
    if shape == "circle":
        rad = input("what is the radius?")
	area = math.pi * (rad**2)  	
	
    elif shape == "rectangle":
	length = input("what is the length?")
	width = input("what is the width?")
	area = length*width
	if length == width:
            shape = "square"
    elif shape == "triangle":
        length = input("what is the height?")
	width = input("what is the base?")
	area = (height*base)/2
	
    else:
        print "unknown shape"
    if shape == "rectangle" or shape == "triangle" or shape == "circle" or shape == "square": 
        print " the shape is %s the area is %d and this program has been run %d times " % (shape,area,c)
    
    quit = raw_input("do you want to quit? ")
import sys
sys.exit()

there should be tabs in there but dont know how to get them 2 work.