Help with Project


#1

Hello, can someone check my code for this project?

It kept on saying this:

SyntaxError: invalid syntax
$ python AreaCalculator.py
File "AreaCalculator.py", line 34
else:
^
SyntaxError: invalid syntax

"""This is a calculator that can compute the area of a given shape, as selected by the user. The calculator will be able to determine the area of the following shapes: circle and triangle"""

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

now =  datetime.now()

print 'Let\'s start!'

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 the 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 the base of the triangle: "))
height = float(raw_input("Enter the height of the triangle: "))
area = 0.5 * height * base
print "Uni Bi Tri..."          

sleep(1)       
print ("area: %.2f. \n%s" % (area, hint))

else: 
  print "Error! Exiting."

Thank you!!!


#2

The indentation in your elif branch is inconsistent, with many lines being outside of the block.


#3

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