python类导入问题

时间:2016-10-08 22:38:46

标签: python python-3.x

我是python的新手并为学校做一些编程我已经编写了一个名册系统的代码,我应该使用字典。我一直收到错误没有名为'players_Class'的模块 有人能告诉我我做错了吗

class Players:

    def __init__(self, name, number, jersey):
        self.__name = name
        self.__number = number
        self.__jersey = jersey

    def setname(self, name):
        self.__name = name

    def setnumber(self, number):
        self.__number = number

    def setjersey(self, jersey):
        self.__jersey = jersey

    def getname(self):
        return self.__name

    def getnumber(self):
        return self.__number

    def getjersey(self):
        return self.__jersey

    def displayData(self):
        print("")
        print("Player Information ")
        print("------------------------")
        print("Name:", self.__name)
        print("Phone Number:", self.__number)
        print("Jersey Number:", self.__jersey)

    import players_Class

def displayMenu():
        print("1. Display Players")
        print("2. Add Player")
        print("3. Remove Player")
        print("4. Edit Player")
        print("9. Exit Program")
        print("")
        return int(input("Selection> "))

def printPlayers(players):
    if len(players) == 0:
            print("Player not in List.")
    else:

        for x in players.keys():

            players[x].displayData(self)

def addplayers(players):

        newName = input("Enter new Players Name: ")

        newNumber = int(input("Players Phone Number: "))

        newJersey = input("Players Jersey Number: ")
        players[newName] = (newName, newNumber, newJersey)
        return players

def removeplayers(players):
    removeName = input("Enter Player Name to be removed: ")
    if removeName in players:
        del players[removeName]
    else:
        print("Player not found in list.")
        return players

def editplayers(players):


    oldName = input("Enter the Name of the Player you want to edit: ")

    if oldName in players:

        newName = input("Enter the player new name: ")

        newNumber = int(input("Players New Number: "))

        newJersey = input("Players New Jersey Number: ")

        players[oldName] = petClass.Pet(newName, newNumber, newJersey)

    else:

        print("Player Not Found")

        return players



print("Welcome to the Team Manager")

players = {}

menuSelection = displayMenu()


while menuSelection != 9:

    if menuSelection == 1:

        printPlayers(players)

    elif menuSelection == 2:

        players = addplayers(players)

    elif menuSelection == 3:

        players = removeplayers(players)

    elif menuSelection == 4:

        players = editplayers(players)

    menuSelection = displayMenu()

print ("Exiting Program...")

1 个答案:

答案 0 :(得分:0)

你没用过

import players_Class
代码中的

语句。擦掉它!