【发布时间】:2020-07-05 20:39:45
【问题描述】:
当我尝试运行代码时,我不断收到同样的错误消息 NameError: name 'Jan' is not defined 有人可以告诉我如何解决这个问题
def main():
# imports ability to read text files
import csv
times=[1,273,93,59,266,128,2,41,110,315,43,263,3,78,649,620,538,502,4,456,648,618,537,501,5,238,156,160,310,127,6,768,647,616,534,459,7,6785,646,614,533,458,8,567,645,613,531,457,9,700,644,612,530,457,10,678,643,610,529,456,11,78,642,609,527,455,12,659,641,608,526,454,13,6543,640,606,525,453,14,567,639,605, 524,453,15,533,638,604,522,452,16,246,637,602,521,451,17,5,636,601,520,450,18,90,635,600,519,450,19,7,634,558,517,449]
dates = [Jan,Feb,March,April,May]
raceTimes = (input("PLease enter a time you would like to search for:"))
found = False
# open text file
with open("sun_data.csv") as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
# reads the text file
for row in readCSV:
# comparing values in text file with the user-entered time
found = True
for i in range(len(years)):
if years[i] == x:
found = True
print(str(x) + " was found at position " + str(i))
break
if not found:
print("I'm sorry, there is no race scheduled at that time.")
# Close input file
csvfile.close()
main()
【问题讨论】:
-
Jan是一个名为 Jan 的变量。"Jan"(引用)是一个字符串。 -
这是否意味着我需要在 Jan 或括号中添加引号