Angel Tashev
Angel Tashev

Reputation: 3

If statement is not working in Python

I just got a Codeacademy Pro account and I got to make an Area Calculator. Because Codeacademy uses Python 2, I translated the code to fit the Python 3 standarts and I still get an error on line 7 - the if statement has an invalid syntax. Any ideas? Thanks!

"""This program calculates the area of a circle or a triangle."""

print("Area calculator starting up")

option = (input("Enter C for Circle or T for Triangle: ").lower()

if option == "c":
  radius = float(input("Enter circle's radius: "))
  pi = 3.14
  area = pi * radius ** 2
  print ("The area of this circle is : " + str(area))
elif option == "t":
  base = float(input("Enter the triangle's base: "))
  height = float(input("Enter the triangle's height: "))
  area = 0.5 * base * height
  print ("The area of this circle is: " + str(area))

else: 
  print ("Invalid shape!")

print ("The program is exiting!")

Upvotes: 0

Views: 65

Answers (2)

Taohidul Islam
Taohidul Islam

Reputation: 5414

Remove the extra opening parenthesis ( from line 5. It will solve your problem. Your extra opening parenthesis expecting corresponding closing parenthesis ),because of not getting the parenthesis it's showing error on the next line.

Upvotes: 0

t7t0t0t7t
t7t0t0t7t

Reputation: 362

The problem lies above the "if" section:

option = (input("Enter C for Circle or T for Triangle: ").lower()

should be :

option = input("Enter C for Circle or T for Triangle: ").lower()

Upvotes: 3

Related Questions