0

When I go to input 'T' or 't' to go into the triangle prompts, regardless of what I input, the program immediately goes into the calculation for circle.

When I change the IF statement to only accept one character, such as lowercase 't' or 'c' it works randomly, but I want to ensure that the user can input upper or lowercase.

What am I doing wrong? I am using python 2.

#This program calculates the area and other information for 
geometric shapes 
# python AreaCalculator.py
option = raw_input("Enter C for circle or T for triangle ")
print option #this is just to ensure the program is updating the 
variable
if option == 'c' or 'C':
    radius = float(raw_input("Enter the radius of your circle "))
    area = 3.14159 * radius**2
    print "The area of your circle is %f units" % (area)
elif option == 't' or 'T':
    base = float(raw_input("Enter base "))
    height = float(raw_input("Enter height  "))
    area = .5*base*height
    print "The area of the triangle is %f units" % (area)
else:
    print "Invalid"
print "Program complete, please come again"

The result from inputting T or t into option = raw_input just puts me into the if statement pertaining to the circle

Mr. J
  • 1,524
  • 2
  • 19
  • 42
  • replace if & elif conditions , change if condition to if option == 'c' or option == 'C': & change elif condition to elif option == 't' or option == 'T': – dev_user Aug 23 '19 at 05:54
  • just put option.lower() in your if Statement, and remove 'C' and 'T'.... then it won't matter if the user types in uppercase or lower case – Mr. J Aug 23 '19 at 06:07

0 Answers0