无效的语法(字符串和浮点并发症!)

时间:2014-11-03 00:34:22

标签: python

我似乎无法弄清楚这一点。任何帮助是极大的赞赏。

pitcherSpeed=float(round((40908/tempSpeed),2))
output=output+tempPitcher+ "\t" +str(round(float(tempSpeed), 2)) + "\t" +str(round(float(pitcherSpeed), 2)) +"\n"

我遇到上述两行问题。无论我做什么来改变它们。他们错了。我需要一些帮助来确定他们的错误!

以下是我的所有代码(如果需要):

output=""
pitcherSpeed=1
tempPitcher=input("Enter the name of the next contestant, or nothing to exit: ")
fastestSpeed=0
slowestSpeed=0
if tempPitcher=="":
    exit()
fastestPitcher=tempPitcher
slowestPitcher=tempPitcher
tempSpeed=float(input("Enter the time for " +str(tempPitcher) + "'s speed in milliseconds: "))
fastestSpeed=tempSpeed
slowestSpeed=tempSpeed
while tempPitcher!="":
    output=""
    tempPitcher=input("Enter the name of the next contestant, or nothing to exit: ")
    tempSpeed=input("Enter the time for " +str(tempPitcher) + "'s speed in milliseconds: ")
    pitcherSpeed=float(round((40908/tempSpeed),2))
    output=output+tempPitcher+ "\t" +str(round(float(tempSpeed), 2)) + "\t" +str(round(float(pitcherSpeed), 2)) +"\n"  
if tempPitcher!="":
    tempSpeed=input("Enter the time for " +str(tempPitcher) + "'s speed in milliseconds: ")
    if tempSpeed==fastestSpeed:
        fastestSpeed=tempSpeed
        fastestPitcher=tempPitcher
        if tempSpeed==slowestSpeed:
            slowestSpeed=tempSpeed
            slowestPitcher=tempPitcher
print("Name" + "\t" +"Time" +"\t" +"Speed" + "\n" + "===========================" + "\n")
print(output)               
print("Slowest pitcher is " +str(slowestPitcher) +"at" +str(slowestSpeed) +"miles per hour")
print("Fastest pitcher is " +str(fastestPitcher) +"at" +str(slowestSpeed) +"miles per hour")

我收到错误消息: Traceback(最近一次调用最后一次):   文件“C:/Users/whitney.meulink/Desktop/programpractice.py”,第17行,in     pitcherSpeed =浮子(圆((40908 / tempSpeed),2)) TypeError:/:'int'和'str'

的不支持的操作数类型

1 个答案:

答案 0 :(得分:2)

该行:

pitcherSpeed=float(round((40908/tempSpeed),2)

缺少结束括号。

pitcherSpeed=float(round((40908/tempSpeed),2))

通常情况是错误发生在前一行。