2014-12-06 51 views
-1

我不明白爲什麼我一直在第78行的Python 3程序中收到此語法錯誤。我試圖用兩個參數調用函數。語法錯誤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") 

回答

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

你缺少上一行右括號。

+0

非常感謝你!我沒有意識到一個錯誤可能超出了錯誤聲明的範圍。 – flamingjune5dwj 2014-12-06 05:14:49