0

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)
3
  • Please provide your full python code to figure the error. Commented Jun 2, 2020 at 1:52
  • Edited to add full code... Commented Jun 2, 2020 at 1:55
  • It would help if include (cut and paste) the full exact error that you received. Commented Jun 2, 2020 at 2:04

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.