am trying to get the minimum stake on n games using a while loop and recursion function, but it seems like my code is not proceeding like i intended when it comes to recursion bit....any help
i tried redefining the variables after increasing the x variable in the while loop before calling the recursion function as return Product() but in vain
i expected to get several lines of 'Trying again' with a different total stake then at last a list of tickets, but instead i get only only one line and an empty list
from itertools import product
# from csv import writer
data = product(
(('home1', 1.53),( 'away1', 2.4)), #half time
(('home2', 1.53),( 'away2', 2.4)), #half time
(('home3', 1.653),( 'away3', 2.4)), #half time
(('home4', 1.653),( 'away4', 2.4)), #half time
(('home5', 1.653),( 'away5', 2.4)), #half time
)
def check(list1, val):
possible_return = []
for lst in list1:
possible_return.append(lst[-1])
# print(possible_return)
return all(i > val for i in possible_return)
def Product():
x = 1
while True:
dict_of_tickets = {}
list_of_tickets = []
total_Stake = 0
list_of_Odds =[]
pay_out_list = []
for ticket in data:
TOTAL_ODDS = 1
n = 2 ** len(ticket)
for i in ticket:
TOTAL_ODDS = round((TOTAL_ODDS * i[1]), 3)
list_of_Odds.append(TOTAL_ODDS)
odd_per_ticket = TOTAL_ODDS
if odd_per_ticket <= n:
stake = ((n / odd_per_ticket)*x)
pay_out = round(((odd_per_ticket+odd_per_ticket/4)*stake),0)
pay_out_list.append(pay_out)
total_Stake += stake
reciept = [ticket, odd_per_ticket, stake, pay_out]
list_of_tickets.append(reciept)
else:
stake = x/2
pay_out = round(((odd_per_ticket+odd_per_ticket/4)*stake),0)
pay_out_list.append(pay_out)
total_Stake += stake
reciept = [ticket, odd_per_ticket, stake, pay_out]
list_of_tickets.append(reciept)
# print(ticket)
# print('==========================================================')
# print(list_of_tickets)
if check(list_of_tickets, total_Stake):
return list_of_tickets
else:
print("Trying again....!", total_Stake)
x *= 1.5
dict_of_tickets = {}
list_of_tickets = []
total_Stake = 0
list_of_Odds =[]
pay_out_list = []
return Product()
Product()