【发布时间】:2023-04-02 15:40:01
【问题描述】:
我已尝试使用此代码解决作业:
bank_holiday= [1, 0, 1, 1, 2, 0, 0, 1, 0, 0, 0, 2] #gives the list of bank holidays in each month
def bank_holiday(month):
month -= 1#Takes away the numbers from the months, as months start at 1 (January) not at 0. There is no 0 month.
print(bank_holiday[month])
bank_holiday(int(input("Which month would you like to check out: ")))
但是当我运行它时,我得到了错误:
TypeError: 'function' object is not subscriptable
我不明白这是从哪里来的......
【问题讨论】:
-
我需要知道我的代码出了什么问题。
-
这很简单,你有 2 个同名对象,当你说:bank_holiday[month] python 认为你想运行你的函数并得到错误。只需将您的数组重命名为 bank_holidays
标签: python