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:局部变量&#39; is_won&#39;在分配前引用
答案 0 :(得分:0)
问题出在profit == 0
时。在这种情况下,将不会定义is_won
。此外,你的缩进搞砸了。