SyntaxError : invalid syntax


It gives me this error : "SyntaxError : invalid syntax" at line 19

I expect elif to run.

"""This program is a calculator that will compute the area of a given shape, as selected by the user. The calculator can determine that area of circles and triangles."""
from math import pi
from time import sleep
from datetime import datetime
now =
print "The calculator is starting up."
print '%s/%s/%s %s:%s' % (now.month,, now.year, now.hour, now.minute)
hint = "Don't forget to include the correct units!"
print "Enter C for Circle or T for Triangle: "
option = raw_input("Enter C for Circle or T for Triangle: ")
option = option.upper()
if option == 'C':
	radius = float(raw_input("Input a radius: "))
	area = (radius ** 2) * pi
	print "The pie is baking. . . "
	sleep (1)
print ("Area: %.2f. \n%s" % (area, hint))
elif option == 'T':
	base = float(raw_input("Input a base: "))
	height = float(raw_input("Input a height: "))
	area = base * height
	print "Uni Bi Tri. . . "
	sleep (1)
print ("Area: %.2f. \n%s" % (area, hint))
	print "Invalid input. Terminating program. . . "


The reason why python is not happy with your elif is because the previous line is not indented. Thus the opening if is implicitly closed and that 's why there is an error with the elif. The same problem occurs at line 26 with the else.

By the way, the surface of a triangle is base * height / 2 :slight_smile:




when I run my code I obtain:

$ python
File "", line 19
print ("Area: %.2f. \n%s" % (area,hint))
IndentationError: unexpected indent

My line 19 is the print() before the elif. I don't understand what is wrong since the print is properly indented.

if option == 'C':
      radius = float(raw_input("Enter the radius:"))
      print ("Area: %.2f. \n%s" % (area,hint))
elif option == 'T':
      base = float(raw_input("Enter the base:"))
      print ("Area is = %.2f. \n %s" % (area,hint))


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