vendredi 18 octobre 2019

Why is my IF statement in Python not working? [duplicate]

This question already has an answer here:

So I have an assignment to draw a flag using Turtle in Python. I have a variable named flagName and you can use it to select what type of flag you want to draw. But the problem is, the IF statement isn't working! No matter what I type in the variable, it will always print "usa" (My other flags are still work in progress).\
Someone please help me!

speed(0)
penup()
shape("classic")
flagName = "USA"




if flagName == "USA" or "usa" or "United States of America" or "united states of america" or "United States of America" or "us" or "US":
        #setup location
        print("usa")
elif flagName == "China" or "china":
        #setup location
        print("china")
elif flagName == "Germany" or "germany":
        print("germany")
elif flagName == "Canada" or "canada":
        print("canada")
        #setup location
        left(180)
        forward(200)
        right(90)
        forward(100)
        right(90)

        #draw bangs
        for i in range(2):
            forward(400)
            right(90)
            forward(200)
            right(90)
        forward(100)
        right(90)
        forward(200)
        left(90)
        forward(200)
        left(90)
        forward(200)
        backward(1)
        right(90)
        forward(1)
        penup()
        color("red")
        begin_fill()
        for i in range(2):
            forward(100)
            right(90)
            forward(200)
            right(90)
        end_fill()
        backward(300)
        begin_fill()
        for i in range(2):
            forward(100)
            right(90)
            forward(200)
            right(90)
        end_fill()

        #draw black outline
        pendown()
        color("black")
        pensize(2)
        for i in range(2):
            forward(400)
            right(90)
            forward(200)
            right(90)

        pensize(1)
        penup()
        right(90)
        forward(200)
        left(90)
        forward(200)
        left(90)

        #position leaf
        forward(35)
        #------------

        #LEAF
        begin_fill()
        #leaf handle
        color("red")
        pendown()
        left(90)
        forward(5)
        right(90)
        #leaf body bottom
        forward(25)
        left(90)
        forward(25)
        right(110)
        forward(20)
        left(90)

        #draw leaf arms
        for i in range(3):
            if i == 1:
                forward(45)
            else:
                forward(40)
            right(135)
            forward(10)
            left(90)
            forward(20)
            right(120)
            forward(20)
            left(90)
            forward(15)
            right(130)
            if i == 1:
                forward(45)
            else:
                forward(40)
            left(145)
        right(145)
        left(90)
        forward(20)
        right(105)
        forward(25)
        left(90)
        forward(24)
        right(90)
        forward(5)
        end_fill()
        penup()
        forward(1000)
else:
    print("Something happened and weird n stuff.")

Aucun commentaire:

Enregistrer un commentaire