Hello I am new to python and need some help with a basic program (I dont know if this is really the correct forum but I couldnt make an account on some other ones)
I am making a text based idle adaption of the game 21. I want to use a function to easily count the scores of the player / computer. This is the bit of the program I am having issue with:
This is the points list for reference
points = [ ]
p=4
while p != 0:
points.append("ace")
for o in range(2,11):
points.append(o)
i = [10, 10, 10]
points.extend(i)
p=p-1
It is meant to reset the players points and recount it.
def count(a,b):
a = 0
aces = 0
for z in b:
if points[z] != "ace":
a = a + points[z]
else:
aces = aces + 1
if aces == 1:
if a > 10:
a = a + 1
else:
a = a + 11
if aces == 2:
if a > 9:
a = a + 2
else:
a = a + 12
if aces == 3:
if a > 8:
a = a + 3
else:
a = a + 13
if aces == 4:
if a > 7:
a = a + 14
else:
a = a + 4
An example of how I would use it
hand = [0,1,2,3,4,5,6,7,8,9,10,11,12]
player_points = 0
count(player_points,hand)
print(player_points)
It doesnt work and would keep the points at 0, I know this may be very wrong but please help.
Basic python help
Re: Basic python help
This isn't a general python help form, but rather focused on micropython in particular.
I recommend that you head on over to: http://www.reddit.com/r/learnpython
You also really need to preview your post before you post it. Put your code inside otherwise it loses all of the indentation, which makes it really hard to even read the code.
I recommend that you head on over to: http://www.reddit.com/r/learnpython
You also really need to preview your post before you post it. Put your code inside
Code: Select all