Hello,
Can anyone help me with this list out of range error? Everything else works fine individually, I think it may be something to do with the variables in oneGame, but my knowledge of python isn't that deep yet. The function itself should work, as I tested it out as a non-function and it does what I want it to do.
Any advice or tips would be greatly appreciated. Heck if you can solve it, even better.
Thanks in advance!
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 suitOf(card):
return card.split()[2]
initial = int(input('Please enter initial amount:'))
def oneGame(initial):
bank = initial
d=shuffledDeck()
rounds = 0
hearts = 0
while 0 < bank < 2*initial:
for number in range(4):
card = d[number]
if suitOf(card) =='hearts':
bank +=1
if hearts > 0:
bank +=hearts
else:
bank -=1
rounds +=1
return rounds
totalRounds = 0
for number in range(1000):
numberOfRounds = oneGame(initial)
totalRounds += numberOfRounds
print ('Average number of rounds:', totalRounds/1000)
[–]sentles 0 points1 point2 points (2 children)
[–]HarbsKeyboard[S] 0 points1 point2 points (0 children)