From 663cb11aef41d9f2014d316457fa0938987a6f05 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:40:06 +0000 Subject: [PATCH] Multiple bets implemented --- 1ano/1semestre/fp/.idea/csv-editor.xml | 16 ++++++++++++ 1ano/1semestre/fp/.idea/vcs.xml | 2 +- .../fp/extra2/apostas_jornadas/jornada1.csv | 9 +++++++ .../fp/extra2/apostas_jornadas/jornada2.csv | 9 +++++++ 1ano/1semestre/fp/extra2/totobola.py | 25 +++++++++++++------ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 1ano/1semestre/fp/.idea/csv-editor.xml create mode 100644 1ano/1semestre/fp/extra2/apostas_jornadas/jornada1.csv create mode 100644 1ano/1semestre/fp/extra2/apostas_jornadas/jornada2.csv diff --git a/1ano/1semestre/fp/.idea/csv-editor.xml b/1ano/1semestre/fp/.idea/csv-editor.xml new file mode 100644 index 0000000..1470e96 --- /dev/null +++ b/1ano/1semestre/fp/.idea/csv-editor.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/1ano/1semestre/fp/.idea/vcs.xml b/1ano/1semestre/fp/.idea/vcs.xml index b2bdec2..c2365ab 100644 --- a/1ano/1semestre/fp/.idea/vcs.xml +++ b/1ano/1semestre/fp/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/1ano/1semestre/fp/extra2/apostas_jornadas/jornada1.csv b/1ano/1semestre/fp/extra2/apostas_jornadas/jornada1.csv new file mode 100644 index 0000000..d6ccc8e --- /dev/null +++ b/1ano/1semestre/fp/extra2/apostas_jornadas/jornada1.csv @@ -0,0 +1,9 @@ +1,X +2,X +3,1X +4,1X +5,2 +6,X2 +7,1 +8,1 +9,1X2 diff --git a/1ano/1semestre/fp/extra2/apostas_jornadas/jornada2.csv b/1ano/1semestre/fp/extra2/apostas_jornadas/jornada2.csv new file mode 100644 index 0000000..14b81fc --- /dev/null +++ b/1ano/1semestre/fp/extra2/apostas_jornadas/jornada2.csv @@ -0,0 +1,9 @@ +1,2 +2,1 +3,X2 +4,1X +5,1X2 +6,1 +7,2 +8,X +9,X diff --git a/1ano/1semestre/fp/extra2/totobola.py b/1ano/1semestre/fp/extra2/totobola.py index 7dbd02b..54c88de 100644 --- a/1ano/1semestre/fp/extra2/totobola.py +++ b/1ano/1semestre/fp/extra2/totobola.py @@ -1,3 +1,9 @@ +""" +This code is in no way optimal. +A lot could be upgraded here. +""" + + def main(): budget = 0 journeys = {} @@ -17,18 +23,21 @@ def get_user_input(journeys: dict, budget: int) -> None: print('Jornada inválida') match_id = 1 + true_bet_count = [0,0] with open(f'apostas_jornadas/jornada{journey_input}.csv', 'w') as f: for match in journeys[journey_input]: while True: - bet = input(f"{match_id} {match[0]} vs {match[1]}: ") - if bet in ['1', 'x', 'X', '2']: - f.write(f"{match_id},{bet if bet != 'x' else 'X'}\n") + bet = input(f"{match_id} {match[0]} vs {match[1]}: ").upper() + if bet in ['1', 'X', '2', '1X', 'X2', '12', '1X2']: + f.write(f"{match_id},{bet}\n") match_id += 1 + if len(bet) != 1: + true_bet_count[len(bet)-2] += 1 break else: print('Aposta inválida') - budget -= 0.4 + budget -= 0.4 * (2**true_bet_count[0] * 3**true_bet_count[1]) print_results(journeys, int(journey_input), budget) @@ -49,13 +58,13 @@ def print_results(journeys: dict, journey: int, budget: int) -> None: if game[1] == match[0] and game[2] == match[1]: bet = bets[str(journeys[str(journey)].index(match)+1)] result = 'CERTO' if ( - (bet == '1' and game[3] > game[4]) - or (bet == 'X' and game[3] == game[4]) - or (bet == '2' and game[3] < game[4]) + ('1' in bet and game[3] > game[4]) + or ('X' in bet and game[3] == game[4]) + or ('2' in bet and game[3] < game[4]) ) else 'ERRADO' if result == 'CERTO': right_bets_count += 1 - print(f'{line_id} {match[0]:>30} {game[3]}-{game[4]} {match[1]:<30}: {bet} ({result})') + print(f'{line_id} {match[0]:>30} {game[3]}-{game[4]} {match[1]:<30}: {bet:<5} ({result})') line_id += 1 if right_bets_count < 7: price = 0