菜单界面播放记录

Menu Interface Player Records

已回答。向前走。谢谢。

def players ():
    for i in range(0, n):
        name = raw_input("enter your name")
        speed = int(input("speed:"))
        accuracy = float(input("accuracy:"))

您的代码中缺少的部分是创建和维护每个类别的玩家列表的部分。在您的 players 函数中,您应该存储它们。

然后,您将有一个玩家列表,您可以查看每个玩家以检查他们是否满足条件 running_speed>running_min

具体来说,您需要定义如何表示玩家。它可以像 tupleclass(或 NamedTuple 或其他)一样简单。然后,在你查询他的特征之后,你可以创建一个球员对象来存储这些特征,你可以把这些特征放在你的球员列表中。

例如:

class Player(object):
    def __init__(self, name, running_speed, passing_acc, shooting_acc):
        self.name = name
        self.running_speed = running_speed
        self.passing_acc = passing_acc
        self.shooting_acc = shooting_acc

然后:

list_of_players = []
def players():
    for i in range(0, n):
        name = raw_input("enter your name")
        running_speed = int(input("running speed:"))
        passing_acc = float(input("passing accuracy:"))
        shooting_acc = float(input("shooting accuracy:"))
        new_player = Player(name, running_speed, passing_acc, shooting_Acc)
        list_of_players.append(new_player)

寻找他们:

def sweepers():
    running_min = int(input("enter speed"))
    for player in list_of_players:
        if player.running_speed >= running_min:
            print(player.name)

也可以是列表理解:

sweepers = [player for player in players if player.running_speed >= running_min]