#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Removing From List


    Hey, I'm making this text-style fighter game.

    I'm trying to figure out how I can remove the names from the list I've selected. For example if I win a fight, the name from the list that i chose is no longer in the list when i proceed to the next fight.

    My definition:

    Code:
    def newFight():
        fighter = ["Zekeo", "Grobak", "Mammouth", "Jahoba", "Geromi", "Laro", "Jordik"]
        print ("Fighters: " + str(fighter))
        answer = input("Choose your figher: ")
        if random.randint(0, 1):
            print ("You Win!")
        else:
            print ("You Lose!")
            nextFight()
    If it helps to see the whole code. Here it is:

    Code:
    import random
    
    
    def menu():
        print ("|--------------------|")
        print ("|    1. New Fight    |")
        print ("|    2. Instructions |")
        print ("|    3. Credits      |")
        print ("|--------------------|")
        answer = " "
        while answer != "1" and answer != "2" and answer != "3":
            answer = input(">>> ")
            if answer == "1":
                newFight()
            elif answer == "2":
                Instructions()
            elif answer == "3":
                Credits()
            else:
                print ("You hit a wrong number, Try again")
    
    
    def Instructions():
        answer = " "
        print ("Just write the names you would like to fight")
        while answer != "New Fight" and answer != "Credits":
            answer = input("New Fight or Credits?")
            if answer == "New Fight":
                newFight()
            elif answer == "Credits":
                Credits()
            else:
                print ("Just write 'New Fight' or 'Credits'.")
    
    def Credits():
        answer = " "
        print ("Made by Eiğur.")
        print ("Class: FOR103")
        while answer != "New Fight" and answer != "Instructions":
            answer = input("New Fight or Instructions?")
            if answer == "New Fight":
                newFight()
            elif answer == "Instructions":
                Instructions()
            else:
                print ("Just write 'New Fight' or 'Instructions'.")
    
          
    def newFight():
        fighter = ["Zekeo", "Grobak", "Mammouth", "Jahoba", "Geromi", "Laro", "Jordik"]
        print ("Fighters: " + str(fighter))
        answer = input("Choose your figher: ") #Byğur şig um ağ velja bardagsmann
        if random.randint(0, 1):
            print ("You Win!")
        else:
            print ("You Lose!")
            nextFight()
    
    
    menu()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Sets are easiest to work with. Does not matter if the object is available.
    Code:
    import random
    
    def newFight():
        win = loss = 0
        fighter = set(["Zekeo", "Grobak", "Mammouth", "Jahoba", "Geromi", "Laro", "Jordik"])
        while 1 < len(fighter):
            print ("Fighters: " + str(fighter))
            champion = input("Choose your figher: ")
            if random.randint(0, 1):
                win += 1
                print ("You Win!")
                fighter = set(list(fighter-set((champion,)))[1:])
                fighter.add(champion)
            else:
                loss += 1
                print ("You Lose!")
                fighter -= set((champion,))
        print('{} won the tournament.'.format(fighter.pop()))
        print('you picked {} winners of {} bouts'.format(win, win+loss))
    
    newFight()
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo