调用函数时语法错误Python 3

时间:2014-12-06 05:03:57

标签: python function syntax-error

我无法理解为什么我在第78行的Python 3程序中不断收到此语法错误。我试图用两个参数调用一个函数。

reportHits(playerList, num)

我已经检查了缩进,间距,冒号,并在线查看,但我所做的一切都没有修复它。

非常感谢任何帮助!

def quit():
    """This function Quits the Baseball Database"""
    print("You are now leaving the Baseball Database")
    print("Program is terminating gracefully...")

def help():
    """This function displays a List of program functions to the user"""
    print("QUIT - to exit the progam")
    print("HELP - to display a list of functions")
    print("INPUT  - to input a file_path")
    print("TEAM - to sort baseball database by team name identifier")
    print("REPORT - to sort baseball database by number of HITS")

def filePath():
    """This function allows users to Input a file"""
    fileObject = input("Please enter the file path to read: ")
    return fileObject

def processInput(filePath):
    """This function processes the Input file"""
    fileHandle = open(fileObject, "r")
    playerList = []
    for line in fileHandle:
        line = line.strip()
        tokens = line.split(";")        
        element = {"NAME":tokens[0].lower().strip(), "TEAM":tokens[1].lower().strip(), "GamesPLAYED":int(tokens[2]), "AtBATS":int(tokens[3]), "RunsSCORED":int(tokens[4]), "HITS":int(tokens[5]), "DOUBLES":int(tokens[6]), "TRIPLES":int(tokens[7]), "HomeRUNS":int(tokens[7])}
        playerList.append(element)
    fileHandle.close()
    return playerList


def reportHits(sortList, n):
    """This function Sorts each dictionary in the playerList by 'HITS'"""
    from operator import itemgetter
    listHits = sorted(sortList, key = itemgetter('HITS'), reverse = True)
    table = listHits
    for n in table[ :n]:
        from tabulate import tabulate
        print(tabulate(table, headers="keys", tablefmt="grid"))


def sortTeams(sortList):
    """This function Sort each dictionary in the playerList by 'TEAM'"""
    from operator import itemgetter
    listTeams = sorted(sortList, key = itemgetter('TEAM'))
    table = listTeams
    from tabulate import tabulate
    print(tabulate(table, headers="keys", tablefmt="grid"))



playerList = None
command = None

print("Welcome to the Baseball Database")
while command != "quit":
    command = input("Please enter a command (Type HELP to list acceptable commands):")
    command = command.strip()
    command = command.lower()
    if command.startswith("quit"):
        quit()
    elif command.startswith("help"):
        help()
    elif command.startswith("input"):
        fileObject = filePath()
        tokens = fileObject.split(" ")
        playerList = processInput(tokens)
        print("Input file has been processed")
    elif command.startswith("team"):
        if playerList != None:
            sortTeams(playerList)
        else:
            print("No players have been added to the list")
            print("Please input a file before using the 'Team' command")
    elif command.startswith("report"):
        if playerList != None:
            num = input(float("How many of the top players do you want to view?")
            reportHits(playerList, num)
        else:
            print("No players have been added to the list")
            print("Please input a file before using the 'Report' command")
    else:
        print("User entered unrecognized command")

1 个答案:

答案 0 :(得分:1)

        num = input(float("How many of the top players do you want to view?")
        reportHits(playerList, num)

您在上一行中缺少一个近似括号。