这个程序有什么问题 - 什么都没发生?

时间:2018-06-04 18:26:42

标签: python python-3.x

我是python编程的绝对初学者(第4周),我试图解决这个问题。我已经在这几天了,但我真的被卡住了。我已将其调试为零错误,但是当我运行时,根本没有任何反应......我在这做错了什么?

roster =[]

def init_(self, name):
  self.name = name

def setName (self,name):
  self.name = name

def getName(self):
  return self.name

def displayData(self):
  print("")
  print(" Player's Information")
  print("***********************")
  print("Player's Name: ", self.name)

def displayMenu():
  print("***Selection Menu***")
  print("1. View current roster")
  print("2. Add a player to the roster")
  print("2. Remove a player from the roster")
  print("3. Change a player name displayed on the roster")
  print("4. Quit")
  print()
  return int(input("Your Choice?"))

def viewRoster():
  print(' '.join(roster))

def addPlayer():
  newName = input("Who will bring honor to the squad?:")
  roster.append(newName)

def removePlayer ():
  removeName = input("Who's off the team?")
  if removeName in roster:
    del roster[removeName]
  else:
    print("Sorry", removeName, "is not on this team")

def editPlayer():
  oldName = input("What name would you like to change? ")
  if oldName in roster:
    newName = input("What is the new name?  ")
    print("Alright,", oldName, "is now called", newName)
  else:
    print("Sorry,", oldName, "was not found. Are you sure you spelled that right?")

1 个答案:

答案 0 :(得分:-1)

您的代码中最大的问题是,虽然您已经定义了很多函数,但您还没有调用一个函数。

此外,第一个功能应该是

def __init__(self, name):

接下来,您需要定义一个类来封装所有函数和名册变量。由于它是一个类,你添加自我。在你的变量之前,比如名册。

然后你可以在其他地方导入这个类并调用函数。