lundi 10 mai 2021

(PROBLEM) python : If statement is appending a string to the wrong list [duplicate]

I am trying to create a war game where you can draft the countries you want to be your allies. I have 2 lists: countries, that has all available countries for the draft; and allies, which holds the countries that you pick.

The problem I am having is that instead of appending 1 country to allies, it appends all of them and leaves the one I picked in countries instead of allies.

The function answers is just a function that makes you choose the whatever is in the countries list and only the countries list.

I want it to be able to take the one country chosen at a time and put it into allies only.

Code:

countries = ['USA', 'AUSTRALIA', 'BRAZIL', 'CHINA', 'INDIA', 'NORTH KOREA', 'RUSSIA', 'SOUTH KOREA', 'TURKEY', 'PAKISTAN', 'IRAN', 'VIETNAM', 'EGYPT', 'SAUDI ARABIA']

allies = []

while 1 < len(countries):

        draft = answers( countries , "Please choose the country you would like as an ally: ALL CAPS! ")

        print(draft)

        #draft = input("Please choose the country you would like as an ally! ALL CAPS!: ")

        if draft == 'USA':

            print("We are adding it to a list")
            allies.append("USA")
        if draft == "AUSTRALIA" or "australia":
            allies.append("AUSTRALIA")
            countries.remove("AUSTRALIA")

Aucun commentaire:

Enregistrer un commentaire