我正在致力于我的计算机程序设计原理课程的最终项目,我花了一个旧项目从列表中找到项目价格并将其转换为显示NFL团队的最终分数。我的Python代码有什么问题?
我的作品第一次代码:
#Start Program
foundItemFlag = False
itemNum = (34, 124, 178, 219, 225)
price = (3.76, 1.29, 4.78, 2.76, 4.51)
input = int(input("Enter the Item Number: "))
for k in range (5):
if input == itemNum[k]:
foundItemFlag = True
print("The item number you've chosen is ", input, "and the price is ", price[k])
if (foundItemFlag == False):
print("Invalid Item Number!")
#End Program
这里是我的,我试图修复转换代码..
#Start Program
foundTeamFlag = False
teamName = ("Bills", "Dolphins", "Patriots", "Jets", "Ravens", "Bengals", "Browns", "Steelers", "Texans", "Colts", "Jaguars", "Titans", "Broncos", "Chiefs", "Raiders", "Chargers")
final = (6-10, 7-9, "12-4", "6-10", "10-6", "10-6", "5-11", "8-8", "12-4", "11-5", "2-14", "6-10", "13-3", "2-14", "4-12", "7-9")
input = int(input("To find your team's final record for last season please type in their name (Ravens, Texans and etc) :"))
for k in range (5):
if input == teamName[k]:
foundTeamFlag = True
print("The ", input, "final record for 2012-2013 was ", final[k])
if (foundTeamFlag == False):
print("Oops, check your team name and try again!")
#End Program
我非常初学者和复制我的代码进入IDLE和收到此错误为NFL代码:
SyntaxError: multiple statements found while compiling a single statement
首先,避免使用一个变量名与方法名称相同。在这种情况下,'input'被用作方法和数据变量。 – BlackVegetable 2013-05-07 14:42:41
我没有得到'SyntaxError'。然而,在你询问团队名称然后尝试将其转换为整数时出现错误。 – mgilson 2013-05-07 14:43:04
您还应该了解字典。而不是两个元组,你可以做一个字典:'final'= {'Bills':'6-10','Dolphins':'7-9'}'然后,'print finals ['Bills']'会打印' 6-10',无需搜索(使用循环)或将名称转换为整数。 – askewchan 2013-05-07 14:45:46