gpt4 book ai didi

python - 简单函数错误

转载 作者:太空宇宙 更新时间:2023-11-03 19:34:44 24 4
gpt4 key购买 nike

代码:

date=int(raw_input("Date:"))
ammount=int(raw_input("Ammount:"))
desc=str(raw_input("Description:"))
account=str(raw_input("Account:"))

def addEntry(date, ammount, desc, account):
transact=open("transactions.txt", "w")
transact.write(date, ammount, desc, account)
transact.close()

addEntry(date, ammount, desc, account)

给出

Traceback (most recent call last):
File "C:\tbank.py", line 11, in <module>
addEntry(date, ammount, desc, account)
File "C:\tbank.py", line 8, in addEntry
transact.write(date, ammount, desc, account)
TypeError: function takes exactly 1 argument (4 given)

我怎样才能让它工作?

最佳答案

date=int(raw_input("Date:"))
ammount=int(raw_input("Ammount:"))
desc=str(raw_input("Description:"))
account=str(raw_input("Account:"))

def addEntry(date, ammount, desc, account):
transact=open("transactions.txt", "w")
transact.write('%s, %s, %s , %s' % (date, ammount, desc, account))
transact.close()

addEntry(date, ammount, desc, account)

关于python - 简单函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4115275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com