我有这样的错误,当我尝试运行我的脚本:类型错误:“builtin_function_or_method”对象不支持项目分配
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
converter()
File "C:\Users\Joan\Documents\School\Computing\Coursework\A453 - Python\Currency Converter.py", line 19, in converter
exchange(currencyList)
File "C:\Users\Joan\Documents\School\Computing\Coursework\A453 - Python\Currency Converter.py", line 33, in exchange
crntItem = currencyList.index[crntCurrency] =+ 1
TypeError: 'builtin_function_or_method' object does not support item assignment
这里是我的代码,一个未完成的货币换算:
# Global ist
currencyList = ["Pound Sterling", 1, "Euro", 1.22, "US Dollar", 1.67, "Japanese Yen", 169.9480]
#################################
# A program to convert currency #
# Main function #
#################################
def converter():
currencyList = ["Pound Sterling", 1, "Euro", 1.22, "US Dollar", 1.67, "Japanese Yen", 169.9480]
print("1) Enter an amount to be exchanged.")
print("2) Change exchange rates.")
choice=0
while choice==0:
selected=int(input("Please select an option: "))
if selected == 1:
choice = 1
exchange(currencyList)
#################################
# Giving exchanged rate #
#################################
def exchange(currencyList):
crntAmnt = int(input("Please enter the amount of money to convert: "))
crntCurrency = ("Please enter the current currency: ")
newCurrency = ("Please enter the currency you would like to convert to: ")
listLength = len(currencyList)
crntItem = currencyList.index[crntCurrency] =+ 1
print(crntItem)
newItem = currencyList.index[newCurrency] =+ 1
print(newItem)
我试图设置一个主要功能作为菜单,然后调用其他子功能来完成相关的选择。我希望得到一些建议,说明这是否是一种好的方法,因为我看到我的老师做了类似的事情,我应该把它写进'if'陈述等。
这是一个好的,正确的方法编码?
什么是* full * traceback? –
'currencyList.index [..]',使用'()'调用一个函数。 –
@AshwiniChaudhary:然后就是'= + 1',这是不正确的Python语法.. –