So I was going through the Projects for the Beginner thread. I settled on this:
"For $2 you get to throw four dice. If the sum of the faces is less than 9, you win $12, otherwise you lose your investment. Should you play this game?"
Simple enough:
def sum(list):
sum = 0
for elem in list:
sum += elem
return sum
def findOdds():
possibles = [ [1,1,1,1], [1,1,1,2], [1,1,1,3], [1,1,1,4], [1,1,1,5], [1,1,1,6], \
[1,1,2,6], [1,1,3,6], [1,1,4,6], [1,1,5,6], [1,1,6,6], \
[1,2,6,6], [1,3,6,6], [1,4,6,6], [1,5,6,6], [1,6,6,6], \
[2,6,6,6], [3,6,6,6], [4,6,6,6], [5,6,6,6], [6,6,6,6] ]
winners = [roll for roll in possibles if sum(roll) < 9]
return len(possibles) / len(winners) * 100.0
if __name__ == "__main__":
print "Only %f %% chance at winning\n" % findOdds()
File "dicegame.py", line 1
possibles = [ [1,1,1,1], [1,1,1,2], [1,1,1,3], [1,1,1,4], [1,1,1,5], [1,
print "Only %f %% chance at winning\n" % findOdds()< 9]\
^
SyntaxError: invalid syntax
That's greek to me. The backslash... thing... bit me before, so I checked that--thinking maybe I didn't hit return immediately after. That's not it, and my list looks fine. Hopefully you people will see something I don't.
I'm using python 2.2.1