关闭文件的语法无效

时间:2014-10-22 06:37:44

标签: python

def td():

    choice = input("which trainning event would you like to access?\nswimming\ncycling\nrunning\n")
    if choice == "swimming":
     Swimming_file= open("Swimming_file.txt", "w")

totaldistance = input("what was the total distance you swam in meters?")
totaltime = input("how long did you swim for in minutes?")

total = (totaldistance, toataltime)
Swimming_file.write(str(total)
Swimming_file.close() 
td() 

它一直在说游泳file.close()是语法错误,任何人都可以帮忙吗?

3 个答案:

答案 0 :(得分:1)

您在Swimming_file.write(str(total)

之后忘记了一个右括号

答案 1 :(得分:0)

问题出在close()上面的行中:

Swimming_file.write(str(total)

缺少右括号。

答案 2 :(得分:0)

你错过了一个')'。如果您使用的是IDE,则应突出显示它并进行提示。

Swimming_file.write(str(total))