Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x “如何让用户选择与相同的恶棍重新展开战斗。”_Python 3.x - Fatal编程技术网

Python 3.x “如何让用户选择与相同的恶棍重新展开战斗。”

Python 3.x “如何让用户选择与相同的恶棍重新展开战斗。”,python-3.x,Python 3.x,我不知道如何重新运行上面有相同列表的代码 import random import sys def game(): # Welcome sentence to this game print ("Welcome!! to the game." + " In this game you can enter a list of villains to fight Avengers in a battle." + " At the end of the game we could

我不知道如何重新运行上面有相同列表的代码

import random
import sys

def game():
    # Welcome sentence to this game 
    print ("Welcome!! to the game." + " In this game you can enter a list of villains to fight Avengers in a battle." + " At the end of the game we could see who won the most of the battles in the game, and then we could announce the winner.")
    # list of avengers
    Avengers = ["Iron Man", "Hulk", "Spider Man", "Loki", "Clint Barton", "Thor", "Nick Fury", "Black Widow", "Robin", "Cyclops"]
    #list of verbs
    Verbs = ["Sliced", "Stabbed", "Smashed", "Punched", "Bursted", "Blasted", "Escaped", "Doged", "Kicked", "Clouted"]
    # list of Villains from user's input
    Villains = []
    numVillains = 10

    #receive input from user to create list of villians
    for i in range(numVillains):
        Villains.append(input("Enter a Villan's name " + str(i + 1) + ": "))


    # Characters lose the game if they reach the sore of zero first
    Villains = Avengers

    while len(Avengers) > 0 or len(Villains) > 0:
        Avenger = (Avengers [random.randint(0,len(Avengers)-1)])
        Villain = (Villains [random.randint(0,len(Villains)-1)])
        Verb = (Verbs [random.randint(0,len(Verbs)-1)])                
        #Select a winner [TODO]

        if random.choice([True, False])== True:
                print(Avenger + " " + Verb+ " " + Villain )
                while Avenger: #Delete the avengers from the list after it loses in the battle
                    Avenger1 = Avengers.index(Avenger)
                    del Avengers[(int(Avenger1))]
                    break
                print ("Avengers left in the game: " + str(len(Avengers)))
                print ("Villains left in the game: " + str(len(Villains)))

        else:
                print(Villain + " " + Verb+ " " + Avenger )
                while Villain: #Delete the Villains from the list after it loses in the battle
                    Villain1 = Villains.index(Villain)
                    del Villains[(int(Villain1))]
                    break
                print ("Avengers left in the game: " + str(len(Avengers)))#prints no.of Avengers left in the game
                print ("Villains left in the game: " + str(len(Villains)))#prints no.of Villains left in the game

        print(' ')

        if len(Villains) == 0: # if villains reach the score of 0 then the avengers win the game
            print (' Avengers won the game successfully.')
            print ('Amazing!!! you won this game because Villains were defeated by Avengers.')


        if len(Avengers) == 0: # if avengers reach the score of 0 then the villains win the game
            print ('Villains won the game sucessfully.')
            print ('Ohhhh, you lost this game because Avengers were defeated by the Villains.')
game()
把你的游戏功能放在一个循环中


恶棍=复仇者-你调试了这个语句并查看它的功能了吗?那需要重新输入恶棍-代码还有很多其他问题。。。
while True:
    game()