Python函数和格式不起作用

时间:2019-03-18 17:31:26

标签: python

我目前在python中遇到函数问题。这是我尝试将其放入函数之前的代码:

for i in range(4):
    for y in Days:
      for x in "ABCDEF":
        data = input("What was the punctuality for bus " + x + " on " + str(y) + ", Week " + str(Week) + "? ")
        Bus = "Bus" + str(x)
        Buses[Bus].append(str(data))
        print()
    Week += 1

它的工作与预期的一样,但是我尝试将其放在函数中:

def InputData():
  for i in range(4):
    for y in Days:
      for x in "ABCDEF":
        data = input("What was the punctuality for bus " + x + " on " + str(y) + ", Week " + str(Week) + "? ")
        Bus = "Bus" + str(x)
        Buses[Bus].append(str(data))
        print()
    Week += 1

整个星期+ = 1部分我都出错了。他们说:

[pyflakes] local variable 'Week' (defined in enclosing scope on line 11) 
referenced before assignment
[pyflakes] local variable 'Week' is assigned to but never used

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

Week = 0

将此代码放在代码的开头。