调用函数时出现语法错误Python 3
我无法理解为什么在第78行的Python3程序中不断出现这种语法错误。我试图调用一个具有两个参数的函数调用函数时出现语法错误Python 3,python,function,syntax-error,Python,Function,Syntax Error,我无法理解为什么在第78行的Python3程序中不断出现这种语法错误。我试图调用一个具有两个参数的函数 reportHits(playerList, num) 我已经检查了缩进、间距、冒号,并在网上查看了一下,但我所做的一切都没有修复它 非常感谢您的帮助 def quit(): """This function Quits the Baseball Database""" print("You are now leaving the Baseball Database")
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")
上一行缺少一个右括号。非常感谢!!我没有意识到错误可能在声明错误所在的线之上。
num = input(float("How many of the top players do you want to view?")
reportHits(playerList, num)