lundi 11 septembre 2017

Python-My IF statement isnt working [duplicate]

This question already has an answer here:

   import math
def maths():
  shape=input("Choose a shape:Square, Circle or Triangle ")
  if shape == "Triangle" or "triangle":
    triangleb = int(input("How many cm's is the base of your triangle? "))
    triangleh = int(input("How many cm's is the height of your triangle? "))
    t_area = triangleb*triangleh / 2
    print("The area of your triangle is",t_area)
    print("")
    maths()

  elif shape == "Circle" or "circle":
    circle=int(input("What is the radius of your circle? "))
    c_area=math.pi*circle*circle
    c_arearound=round(c_area ,2)
    print("The area of your circle is",c_arearound,"(rounded to 2 decimal places)")
    print("")
    maths()

 elif shape == "square" or "Square":
    square=int(input("How many cm is one side of your square "))
    s_area=square*square
    print("The area of your square is",s_area)
    print("")
    maths()
 else:
    print("invalid answer")
    maths()

maths()   

Each element of the IF statement works exactly correctly when they start with 'if. The problem is that if I input 'circle' the code for triangle will appear. For example I would type circle and it would say 'how many cm's is the base of your triangle?'. This happens for whatever I type whether its circle or square it will print the code for triangle. If I switch the 'if' statement for the circle instead of triangle the exact same happens. I could input triangle or square and it would run the code for circle only, whatever the input is. Why??

Aucun commentaire:

Enregistrer un commentaire