Matteo
Matteo

Reputation: 1136

Bad input error in Python 2.7 in multiple inputs

I am taking an intro course in Python and the assignment is to figure the area I have the inputs working, but I'm getting an error on the first elif (triangle). It has something to do with the data type, but I'm new to Python and would appreciate a hand...

def get_shape(input):
  #print("You entered %s inside the function.") % (input)
  return input.upper()
allowed_shapes = ["C", "T", "R"]
print
print("Let's calculate the area of a shape!")
print
print("Enter \"C\" for a circle, \"T\" for a triangle, or \"R\" for a rectangle...")
print
shape = get_shape(input = raw_input("Enter a shape:"))

while shape not in allowed_shapes:
  print("You must enter either a (C)ircle, (T)riangle or (R)ectangle.")
  print
  shape = get_shape(input = raw_input("Enter a shape:"))

if shape == "C":
  print("You chose C.")
  radius = float(raw_input("Enter the radius of the circle...:"))
  print
  print "The area of your circle is %f square units." % ((radius**2) * 3.14159)
elif shape == "T":
  print("You chose T.")
  t_base = float(raw_input("Enter the base of the triangle...:"))
  t_height = float(raw_input("Enter the height of the triangle...:"))
  print
  print "The area of your triangle is %f square units." % ((t_base * t_height) / 2))
else:
  print("You chose R.")
  legnth = float(raw_input("Enter the legnth of the rectangle...:"))
  width = float(raw_input("Enter the width of the rectangle...:"))
  print
  print "The area of your rectangle is %f square units." % (legnth * width)

Upvotes: 0

Views: 40

Answers (1)

You have got an extra round bracket here

print "The area of your triangle is %f square units." % ((t_base * t_height) / 2))

It should look like this

print "The area of your triangle is %f square units." % ((t_base * t_height) / 2)

Upvotes: 1

Related Questions