Basic python help

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
haskell
Posts: 1
Joined: Tue Jan 27, 2015 10:15 pm

Basic python help

Post by haskell » Tue Jan 27, 2015 10:21 pm

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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Basic python help

Post by dhylands » Wed Jan 28, 2015 7:26 pm

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.

Post Reply