mardi 23 février 2021

Beginner Python - Expecting user input after true if statement

I'm very new to coding and I'm looking to receive input from the user only after an if-statement returns true. However this doesn't seem to work, I get to enter just one input after entering either "rectangle" or "triangle" - What is wrong? Thank you in advance

type = input()
pi = 3.14159
area = 0

if type == "square" or "circle":
    side = float(input())
    if type == "square":
        area = side * side
    elif type == "circle":
        area = pi * side * side
elif type == "rectangle" or "triangle":
    side1 = float(input())
    side2 = float(input())
    if type == "rectangle":
        area = side1 * side2
    elif type == "triangle":
        area = (side1 * side2) / 2
print (f"{area:.3f}")    

P.S. - Code is properly indented in the IDE

Aucun commentaire:

Enregistrer un commentaire