Please help, I'm new to python and I've been trying to figure this out for HOURS.
I must create a program that follows these rules:
1. The game starts with certain initial amount of dollars.
2. At each round of the game, instead of flipping a coin, the player shuffles a deck and draws 6 cards. If the drawn hand contains at least one ace, the player gains a dollar, otherwise they lose a dollar.
3. The game runs until the player either runs out of money or doubles their initial amount.
To test the game, given the initial amount, run it 1000 times to determine how many rounds does the game last on average.
This is my code:
Example of running the CORRECT program:
Enter initial amount: 10
Average number of rounds: 46.582
Enter initial amount: 20
Average number of rounds: 97.506
I must create a program that follows these rules:
1. The game starts with certain initial amount of dollars.
2. At each round of the game, instead of flipping a coin, the player shuffles a deck and draws 6 cards. If the drawn hand contains at least one ace, the player gains a dollar, otherwise they lose a dollar.
3. The game runs until the player either runs out of money or doubles their initial amount.
To test the game, given the initial amount, run it 1000 times to determine how many rounds does the game last on average.
This is my code:
import random faceValues = ['ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king'] suits = ['clubs', 'diamonds', 'hearts', 'spades'] def shuffledDeck(): deck = [] for faceValue in faceValues: for suit in suits: deck.append(faceValue + ' of ' + suit) random.shuffle(deck) return deck def faceValueOf(card): return card.split()[0] def suitOf(card): return card.split()[2] def game(initial): bankroll = initial counts = 0 suma = 0 while 0 < bankroll < 2*initial: ronda = random.sample(shuffledDeck(), 6) counts += 1 for cards in ronda: if faceValueOf(cards) == 'ace': suma += 1 if suma >= 1: bankroll += 1 else: bankroll -= 1 return counts initial = float(input('Enter initial: ')) totalcounts = 0 for x in range(1000): totalcounts += game(initial) print('Average number of rounds: ', totalcounts/1000)I'm not getting the right values.
Example of running the CORRECT program:
Enter initial amount: 10
Average number of rounds: 46.582
Enter initial amount: 20
Average number of rounds: 97.506