【问题标题】:Code stops all withdrawals even when its not supposed to代码停止所有提款,即使它不应该
【发布时间】:2022-01-20 05:22:27
【问题描述】:

所以我应该实现一段代码来阻止用户从他们的储蓄账户中提取资金超过一个月,但不幸的是,我遇到了困难,无法弄清楚如何解决这个问题。即使唯一的交易是存款,我的代码也会阻止提款。

def okToWithdraw(acc: SavingAccount) -> "bool":
    """Compares two dates then gives the ok"""
    # reads lines of dictionaries and appends the to a list
    myList = openfile("accountTransactions.txt")
    # today's date
    tim = str(date.today())
    # filters through the file so that only transactions
    # from the same account are forwarded
    found_list = search_dic_list(myList, "AccID", acc.acc_ID)
    # if not found, green light and Withdrawal can proceed
    if not found_list:
        return True
    else:
        # here is the problem code
        dic = found_list[len(found_list) - 1]
        if days_between(tim, str(dic["TransTime"])) >= 30:
            return True
        return False
....
...

def search_dic_list(myList: "list", key: "str", item: "str") -> "list" or None:
    """Searches a dictionary list by its key for a certain value
    returns the found value as a list
    None is it doesnt exist"""
    found_value = []
    found = False
    for dictionary in myList:
        if dictionary[key] == item:
            found_value.append(dictionary)
            found = True
    if found:
        return found_value
    return None



任何帮助将不胜感激 注意:每笔交易都有一个唯一的 ID,该 ID 大部分相同,但会自行递增

trans_id = str(acc.acc_ID) + method + str(tim) + "_" + str(count)
# acc.acc_ID = account class ID ex. "1234_Sav"
# Method = a string ex "_WD_"
# str(tim) = time
# str(count) incrementing index

提前谢谢你!

【问题讨论】:

  • 您的提款是否有任何标识可以帮助发现其他交易之间的差异?
  • 交易ID在那里,谢天谢地。所以这应该会有所帮助。我只是碰壁了,因为无论我尝试什么,它都会向我抛出错误
  • 你搜索只需要account_id,你可以通过操作sum中的“-”找到提款
  • 对不起,我不明白你的意思:(
  • 我想说的是,您可以按操作类型选择所有提款。提现后账户余额低于之前,但另一笔交易增长余额

标签: python python-3.x oop


【解决方案1】:

您可以在found_list中实现查找提现的小功能并更改一些代码:

def okToWithdraw(acc: SavingAccount) -> "bool":
    """Compares two dates then gives the ok"""
    # reads lines of dictionaries and appends the to a list
    myList = openfile("accountTransactions.txt")
    # today's date
    tim = str(date.today())
    # filters through the file so that only transactions
    # from the same account are forwarded
    found_list = search_dic_list(myList, "AccID", acc.acc_ID)
    found_withdrawal = find_withdrawal(found_list)
    # if not found, green light and Withdrawal can proceed
    if not found_withdrawal:
        return True
    else:
        # here is the problem code
        dic = found_list[len(found_list) - 1]
        if days_between(tim, str(dic["TransTime"])) >= 30:
            return True
        return False
def find_withdrawal(transactions: list)->datetime:
    pass

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多