变量赋值问题(Python)

2024-09-28 03:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

def bet(sport,home,away,market,selection,odds,stake,profit,bookie,tipster=None):
    global df
    if profit > 0:
        is_won = True
    elif profit < 0:
        is_won = False
    elif profit == 0:
        None
    temp_df = pd.DataFrame([[sport,home,away,market,selection,odds,tipster,stake,is_won,profit,bookie]], columns=columns_list)
    df = df.append(temp_df, ignore_index=True)
    if profit > 0:
        print("Good bet on %s! :)" %selection)
    elif profit < 0:
        if tipster is not None:
            print("Don't trust %s! :(" %tipster)
        elif tipster is None:
            print("Shame...")
    elif profit == 0:
        print("Cowboys")

返回UnboundLocalError:赋值前引用了局部变量'is\u won'


Tags: nonedfhomeifismarketprintelif
1条回答
网友
1楼 · 发布于 2024-09-28 03:21:18

问题是当profit == 0。在这种情况下,将不定义is_won。而且,你的压痕也弄乱了。你知道吗

相关问题 更多 >

    热门问题