Skip to content

Instantly share code, notes, and snippets.

@brijeshb42
Created March 12, 2014 19:35
Show Gist options
  • Save brijeshb42/9514610 to your computer and use it in GitHub Desktop.
Save brijeshb42/9514610 to your computer and use it in GitHub Desktop.
import random
you = 0
comp = 0
def rollDice():
a = random.randrange(1,7)
b = random.randrange(1,7)
return [a,b]
def get_response():
y = raw_input('\nDo you want to roll (y/n): ')
if y=='y' or y=='Y':
return 1
else:
return 0;
if __name__ == '__main__':
rnd = 1
while True:
if(get_response()):
res = rollDice()
print('Your dice obtained {0} and {1}.'.format(res[0],res[1]))
you = you + res[0] + res[1]
print('You total after round {0} is {1}.'.format(rnd,you))
cp = rollDice()
rnd = rnd+1
comp = comp+cp[0]+cp[1]
if comp>21 and you<comp:
print('I lost. You won. My total is {0}.'.format(comp))
exit()
if you>21 and comp<you:
print('You lost. I won. My total is {0}.'.format(comp))
exit()
else:
break
if (comp>21 and you<comp) or (you<comp):
print('I lost. You won. My total is {0}.'.format(comp))
if (you>21 and comp<you) or (you>comp):
print('You lost. I won. My total is {0}.'.format(comp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment