I need h3lp pls
So for a really important project in school I decided to make a project where I would simulate a scratch card for the awareness of low cost gambling long term and have used so to help but for some reason the odds are not working correctly I have the correct odds in the script but the winnings are way too inflated when trying out the program and can someone help my understand why it doesn’t work? Thanks.
Here is the code:
from flask import Flask, render_template, jsonify import random
app = Flask(name)
Initialize counters
total_cards_used = 0 total_spent = 0 total_winnings = 0
Define prizes and their odds
prizes_and_odds = [ (“FREE €1 Ticket”, 18.18), (“€2”, 8.68), (“€4”, 55.56), (“€5”, 187.50), (“€8”, 500.00), (“€10”, 333.33), (“€20”, 535.71), (“€40”, 8571.43), (“€50”, 15000.00), (“€100”, 75000.00), (“€10,000”, 1500000.00), ]
Total number of cards
total_cards = 1_500_000 card_pool = []
Create winning cards for each prize
for prize, odds in prizes_and_odds: num_winning_cards = int(total_cards / odds) # Calculate how many cards should win this prize for _ in range(num_winning_cards): # Create a winning card with exactly 3 matching prizes and 3 random placeholders winning_card = [prize] * 3 + random.choices([prize for prize, _ in prizes_and_odds], k=3) random.shuffle(winning_card) # Shuffle the card layout card_pool.append(winning_card)
Generate losing cards
num_losing_cards = total_cards – len(card_pool) prize_list = [prize for prize, _ in prizes_and_odds]
for _ in range(num_losing_cards): while True: # Generate a losing card with random prizes losing_card = random.choices(prize_list, k=6) # Ensure no prize appears exactly 3 times if all(losing_card.count(prize) != 3 for prize in set(losing_card)): break card_pool.append(losing_card)
Shuffle the entire pool
random.shuffle(card_pool)
@app.route(“/”) def index(): return render_template(“index.html”)
@app.route(“/scratch”) def scratch(): global total_cards_used, total_spent, total_winnings
card_price = 1 # Define the price of a single scratch card total_cards_used += 1 total_spent += card_price # Draw a random card from the pool selected_card = card_pool.pop() grid_1 = selected_card[:3] grid_2 = selected_card[3:] # Calculate winnings based on the card winnings = 0 for grid in [grid_1, grid_2]: for prize in set(grid): if grid.count(prize) == 3: # Check for exactly three matches if prize == "FREE €1 Ticket": winnings += 1 # Free ticket is equivalent to €1 elif prize is not None: # Ignore None placeholders winnings += int(prize[1:].replace(",", "")) # Convert "€X" to integer total_winnings += winnings # Format the card for display formatted_grid_1 = [prize if prize else " " for prize in grid_1] formatted_grid_2 = [prize if prize else " " for prize in grid_2] # Prepare data to send to frontend scratch_data = { "grid_1": formatted_grid_1, "grid_2": formatted_grid_2, "result": f"€{winnings}" if winnings > 0 else "No Win", "total_cards": total_cards_used, "total_spent": total_spent, "total_winnings": total_winnings, } return jsonify(scratch_data)
if name == “main“: app.run(debug=True)
submitted by /u/snoopdawg694
[link] [comments]
r/learnpython I need h3lp pls So for a really important project in school I decided to make a project where I would simulate a scratch card for the awareness of low cost gambling long term and have used so to help but for some reason the odds are not working correctly I have the correct odds in the script but the winnings are way too inflated when trying out the program and can someone help my understand why it doesn’t work? Thanks. Here is the code: from flask import Flask, render_template, jsonify import random app = Flask(name) Initialize counters total_cards_used = 0 total_spent = 0 total_winnings = 0 Define prizes and their odds prizes_and_odds = [ (“FREE €1 Ticket”, 18.18), (“€2”, 8.68), (“€4”, 55.56), (“€5”, 187.50), (“€8”, 500.00), (“€10”, 333.33), (“€20”, 535.71), (“€40”, 8571.43), (“€50”, 15000.00), (“€100”, 75000.00), (“€10,000”, 1500000.00), ] Total number of cards total_cards = 1_500_000 card_pool = [] Create winning cards for each prize for prize, odds in prizes_and_odds: num_winning_cards = int(total_cards / odds) # Calculate how many cards should win this prize for _ in range(num_winning_cards): # Create a winning card with exactly 3 matching prizes and 3 random placeholders winning_card = [prize] * 3 + random.choices([prize for prize, _ in prizes_and_odds], k=3) random.shuffle(winning_card) # Shuffle the card layout card_pool.append(winning_card) Generate losing cards num_losing_cards = total_cards – len(card_pool) prize_list = [prize for prize, _ in prizes_and_odds] for _ in range(num_losing_cards): while True: # Generate a losing card with random prizes losing_card = random.choices(prize_list, k=6) # Ensure no prize appears exactly 3 times if all(losing_card.count(prize) != 3 for prize in set(losing_card)): break card_pool.append(losing_card) Shuffle the entire pool random.shuffle(card_pool) @app.route(“/”) def index(): return render_template(“index.html”) @app.route(“/scratch”) def scratch(): global total_cards_used, total_spent, total_winnings card_price = 1 # Define the price of a single scratch card total_cards_used += 1 total_spent += card_price # Draw a random card from the pool selected_card = card_pool.pop() grid_1 = selected_card[:3] grid_2 = selected_card[3:] # Calculate winnings based on the card winnings = 0 for grid in [grid_1, grid_2]: for prize in set(grid): if grid.count(prize) == 3: # Check for exactly three matches if prize == “FREE €1 Ticket”: winnings += 1 # Free ticket is equivalent to €1 elif prize is not None: # Ignore None placeholders winnings += int(prize[1:].replace(“,”, “”)) # Convert “€X” to integer total_winnings += winnings # Format the card for display formatted_grid_1 = [prize if prize else ” ” for prize in grid_1] formatted_grid_2 = [prize if prize else ” ” for prize in grid_2] # Prepare data to send to frontend scratch_data = { “grid_1”: formatted_grid_1, “grid_2”: formatted_grid_2, “result”: f”€{winnings}” if winnings > 0 else “No Win”, “total_cards”: total_cards_used, “total_spent”: total_spent, “total_winnings”: total_winnings, } return jsonify(scratch_data) if name == “main”: app.run(debug=True) submitted by /u/snoopdawg694 [link] [comments]
I need h3lp pls
So for a really important project in school I decided to make a project where I would simulate a scratch card for the awareness of low cost gambling long term and have used so to help but for some reason the odds are not working correctly I have the correct odds in the script but the winnings are way too inflated when trying out the program and can someone help my understand why it doesn’t work? Thanks.
Here is the code:
from flask import Flask, render_template, jsonify import random
app = Flask(name)
Initialize counters
total_cards_used = 0 total_spent = 0 total_winnings = 0
Define prizes and their odds
prizes_and_odds = [ (“FREE €1 Ticket”, 18.18), (“€2”, 8.68), (“€4”, 55.56), (“€5”, 187.50), (“€8”, 500.00), (“€10”, 333.33), (“€20”, 535.71), (“€40”, 8571.43), (“€50”, 15000.00), (“€100”, 75000.00), (“€10,000”, 1500000.00), ]
Total number of cards
total_cards = 1_500_000 card_pool = []
Create winning cards for each prize
for prize, odds in prizes_and_odds: num_winning_cards = int(total_cards / odds) # Calculate how many cards should win this prize for _ in range(num_winning_cards): # Create a winning card with exactly 3 matching prizes and 3 random placeholders winning_card = [prize] * 3 + random.choices([prize for prize, _ in prizes_and_odds], k=3) random.shuffle(winning_card) # Shuffle the card layout card_pool.append(winning_card)
Generate losing cards
num_losing_cards = total_cards – len(card_pool) prize_list = [prize for prize, _ in prizes_and_odds]
for _ in range(num_losing_cards): while True: # Generate a losing card with random prizes losing_card = random.choices(prize_list, k=6) # Ensure no prize appears exactly 3 times if all(losing_card.count(prize) != 3 for prize in set(losing_card)): break card_pool.append(losing_card)
Shuffle the entire pool
random.shuffle(card_pool)
@app.route(“/”) def index(): return render_template(“index.html”)
@app.route(“/scratch”) def scratch(): global total_cards_used, total_spent, total_winnings
card_price = 1 # Define the price of a single scratch card total_cards_used += 1 total_spent += card_price # Draw a random card from the pool selected_card = card_pool.pop() grid_1 = selected_card[:3] grid_2 = selected_card[3:] # Calculate winnings based on the card winnings = 0 for grid in [grid_1, grid_2]: for prize in set(grid): if grid.count(prize) == 3: # Check for exactly three matches if prize == "FREE €1 Ticket": winnings += 1 # Free ticket is equivalent to €1 elif prize is not None: # Ignore None placeholders winnings += int(prize[1:].replace(",", "")) # Convert "€X" to integer total_winnings += winnings # Format the card for display formatted_grid_1 = [prize if prize else " " for prize in grid_1] formatted_grid_2 = [prize if prize else " " for prize in grid_2] # Prepare data to send to frontend scratch_data = { "grid_1": formatted_grid_1, "grid_2": formatted_grid_2, "result": f"€{winnings}" if winnings > 0 else "No Win", "total_cards": total_cards_used, "total_spent": total_spent, "total_winnings": total_winnings, } return jsonify(scratch_data)
if name == “main“: app.run(debug=True)
submitted by /u/snoopdawg694
[link] [comments]