所以我的程序基本上从csv文件中获取一堆考试日期,然后将它们存储在列表中。然后我使用csv文件的值作为参数运行我的函数findSchedule。 findSchedule返回一个很好的值,但当我尝试格式化它时,在某些索引上,它返回一个" NoneType"值。这是我的代码:
import csv
def findSchedule(days,time,cr,period):
if days == "TR":
if time == "11:00":
if period == "AM":
return("Tuesday, December 13, 9:45 - 11:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "12:30" or time == "1:00":
if period == "PM":
return("Tuesday, December 13, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "3:30":
if period == "PM":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "5:00":
if period == "PM":
return("Tuesday, December 13, 4:30 - 6:30 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "6:30":
if period == "PM":
return("Tuesday, December 13, 7:00 - 9:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "8:00":
if period == "AM":
return("Wednesday, December 14, 7:30 - 9:30 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "2:00":
if period == "PM":
return("Thursday, December 15, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "9:30":
if period == "AM":
return("Friday, December 16, 9:45 - 11:45 am")
elif time == "9:00":
if period == "AM":
return("Friday, December 16, 7:30 - 9:30 am")
elif time == "10:00":
if period == "AM":
return("Wednesday, December 14, 9:45 - 11:45 am")
elif time == "12:00":
if period == "PM":
return("Wednesday, December 14, 12:00 - 2:00 pm")
elif time == "5:00" and cr == "5":
return("Wednesday, December 14, 4:30 - 6:30 pm")
elif days == "MWF":
if time == "10:00":
if period == "AM":
return("Wednesday, December 14, 9:45 - 11:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "12:00":
if period == "PM":
return("Wednesday, December 14, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "3:00":
if period == "PM":
return("Wednesday, December 14, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "5:00":
if period == "PM":
return("Wednesday, December 14, 4:30 - 6:30 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "6:30" or time == "8:00":
if period == "PM":
return("Wednesday, December 14, 7:00 - 9:00 pm")
elif period == "AM" and time == "8:00":
return("Thursday, December 15, 7:30 - 9:30 am")
elif time == "11:00":
if period == "AM":
return("Thursday, December 15, 9:45 - 11:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "2:00":
if period == "PM":
return("Thursday, December 15, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "9:00":
if period == "AM":
return("Friday, December 16, 7:30 - 9:30 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "1:00":
if period == "PM":
return("Friday, December 16, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "4:00":
if period == "PM":
return("Friday, December 16, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "8:00":
if period == "AM":
return("Thursday, December 15, 7:30 - 9:30 am")
elif time == "9:30":
return("Friday, December 16, 9:45 - 11:45 am")
elif time == "3:30":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif time == "3:00":
return("Wednesday, December 14, 2:15 - 4:15 pm")
elif time == "11:00" and cr == "5":
if period == "AM":
return("Thursday, December 15, 9:45 - 11:45 am")
elif days == "MW":
if time == "8:00":
if period == "PM":
return("Wednesday, December 14, 7:00 - 9:00 pm")
elif period == "AM":
return("Thursday, December 15, 7:30 - 9:30 am")
elif time == "11:00":
if period == "AM":
return("Thursday, December 15, 9:45 - 11:45 am")
elif period == "AM":
return("Class final not found, please try again")
elif time == "2:00":
if period == "PM":
return("Thursday, December 15, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "1:00":
if period == "PM":
return("Friday, December 16, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "10:00":
if period == "AM":
return("Wednesday, December 14, 9:45 - 11:45 am")
elif time == "9:00":
return("Friday, December 16, 7:30 - 9:30 am")
elif time == "9:30":
return("Friday, December 16, 9:45 - 11:45 am")
elif time == "9:30":
return("Friday, December 16, 9:45 - 11:45 am")
elif time == "3:30":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif time == "6:30" and cr == "1":
return("Monday, December 12, 6:30 - 7:25 pm")
elif time == "6:30" and cr == "2":
return("Monday, December 12, 6:30 - 8:20 pm")
elif time == "6:30" and cr == "3":
return("Monday, December 12, 6:30 - 9:30 pm")
elif time == "6:30" and cr == "4":
return("Monday, December 12, 6:30 - 10:15 pm")
elif time == "5:00" and cr == "5":
if period == "PM":
return("Wednesday, December 14, 4:30 - 6:30 pm")
elif days == "R":
if time == "6:30" and period == "PM":
return("Thursday, December 15, 7:00 - 9:00 pm")
elif days == "WF":
if time == "8:00" and (cr == "2" or cr == "5"):
if period == "AM":
return("Thursday, December 15, 7:30 - 9:30 am")
elif period == "PM":
return("No class found")
elif time == "8:00" and cr == "4":
if period == "AM":
return("Wednesday, December 14, 7:30 - 9:30 am")
elif period == "PM":
return("Class not found")
elif time == "9:00":
if period == "AM":
return("Friday, December 16, 7:30 - 9:30 am")
if period == "PM":
return("Class not found")
elif time == "9:30":
if period == "AM":
return("Friday, December 16, 9:45 - 11:45 am")
elif period == "PM":
return("Class not found")
elif time == "10:00":
if period == "AM":
return("Wednesday, December 14, 9:45 - 11:45 am")
elif period == "PM":
return("Class not found")
elif time == "11:00":
if period == "AM":
return("Thursday, December 15, 9:45 - 11:45 am")
elif period == "PM":
return("Class not found")
elif time == "12:00":
if period == "PM":
return("Wednesday, December 14, 12:00 - 2:00 pm")
elif period == "AM":
return("Class not found")
elif time == "12:30":
if period == "PM":
return("Tuesday, December 13, 12:00 - 2:00 pm")
elif period == "AM":
return("Classs not found")
elif time == "1:00":
if period == "PM":
return("Friday, December 16, 12:00 - 2:00 pm")
elif period == "AM":
return("Class not found")
elif time == "2:00":
if period == "PM":
return("Thursday, December 15, 12:00 - 2:00 pm")
elif period == "AM":
return("Class not found")
elif time == "3:00":
if period == "PM":
return("Wednesday, December 14, 2:15 - 4:15 pm")
elif period == "AM":
return("Class not found")
elif time == "3:30":
if period == "PM":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif period == "AM":
return("Class not found")
elif time == "4:00":
if period == "PM":
return("Friday, December 16, 2:15 - 4:15 pm")
elif period == "AM":
return("Class not found")
elif time == "5:00" and cr == "2":
if period == "PM":
return("Tuesday, December 13, 4:30 - 6:30 pm")
elif period == "AM":
return("Class not found")
elif time == "5:00" and cr == "4":
if period == "PM":
return("Wednesday, December 14, 4:30 - 6:30 pm")
elif period == "AM":
return("Class not found")
elif time == "9:30":
return("Friday, December 16, 9:45 - 11:45 am")
elif time == "3:30":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif days == "M":
if time == "6:30":
return("Monday, December 12, 6:30 - 7:25 pm")
elif days == "T":
if time == "6:30":
return("Tuesday, December 13, 7:00 - 9:00 pm")
else:
if (cr == "4" or cr == "2") and time == "12:30":
if period == "PM":
return("Tuesday, December 13, 1:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif cr == "4" and time == "3:30":
if period == "PM":
return("Tuesday, December 13, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif cr == "4" and time == "5:00":
if period == "PM":
return("Tuesday, December 13, 4:30 - 6:30 pm")
elif period == "AM":
return("Class final not found, please try again")
elif cr == "4" and time == "8:00":
if period == "AM":
return("Wednesday, December 14, 7:30 - 9:30 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "10:00":
if period == "AM":
return("Wednesday, December 14, 9:45 - 10:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "12:00":
if period == "PM":
return("Wednesday, December 14, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "3:00":
if period == "PM":
return("Wednesday, December 14, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "5:00":
if period == "PM":
return("Wednesday, December 14, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif cr == "5" and time == "8:00":
if period == "AM":
return("Thursday, December 15, 7:30 - 9:30 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "11:00":
if period == "AM":
return("Thursday, December 15, 9:45 - 11:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif cr == "4" and time == "2:00":
if period == "PM":
return("Thursday, December 15, 12:00 - 2:00 pm")
elif period == "AM":
return("Class final not found, please try again")
elif cr == "5" and time == "2:00":
if period == "PM":
return("Thursday, December 15, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
elif time == "9:00":
if period == "AM":
return("Friday, December 16, 7:30 - 9:30 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "9:30":
if period == "AM":
return("Friday, December 16, 9:45 - 10:45 am")
elif period == "PM":
return("Class final not found, please try again")
elif time == "1:00":
if period == "PM":
return("Friday, December 16, 12:00 - 2:00 pm")
elif period == "PM":
return("Class final not found, please try again")
elif time == "4:00":
if period == "PM":
return("Friday, December 16, 2:15 - 4:15 pm")
elif period == "AM":
return("Class final not found, please try again")
else:
return("Class final not found, please try again")
csvCourses = []
csvExamTime = []
examTime = []
Test = []
with open("final_exam_schedule.csv") as file:
reader = csv.reader(file, delimiter = ",")
next(reader)
for row in reader:
csvCourses.append(row)
for i in range(len(csvCourses)):
csvExamTime.append(csvCourses[i][5])
examTime.append(findSchedule(csvCourses[i][4],csvCourses[i][1],csvCourses[i][3],csvCourses[i][2]))
for i in range(len(csvCourses)):
if examTime[i] == csvExamTime[i]:
Test.append("Pass")
else:
Test.append("False")
print("{0:5}{1:40}{2:60}{3:40}".format("#","Correct Date","Your Date","Test"))
print("~"*110)
for i in range(len(csvCourses)):
print("{0!s:5}{1!s:40}{2!s:60}{3!s:40}".format(int(csvCourses[i][0])-1,csvCourses[i][5],examTime[i],Test[i]))
我知道if / else语句在我的函数中是混乱的(因为我必须为我的项目多次调整它),但请放心,它会返回一个值。当我打印一个给我一个" NoneType"在格式化,调用它的findSchedule函数,它给了我正确的值。那么为什么在我尝试格式化时这个值不会出现呢?