Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2012 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3806407 to your computer and use it in GitHub Desktop.
Save anonymous/3806407 to your computer and use it in GitHub Desktop.
dailyprogrammer#102 solved
from random import randint
import sys
def generateNumber(maxim,minim=1,addorsub=1,value=0):
#addorsub -> 1 is additon, 0 is subtraction
x=randint(minim,maxim)
if value==0:
return x
elif addorsub==1:
return x+value
else:
return x-value
sDice=sys.argv[1]
dsplit=sDice.split('d')
if dsplit[0]=='':
a=1
else:
a=int(dsplit[0])
found=False
if dsplit[1].find('+'):
addorsub=1
found=True
elif dsplit[1].find('-'):
addorsub=0
found=True
if found:
if addorsub==1:
opsplit=dsplit[1].split('+')
else:
opsplit=dsplit[1].split('-')
b=int(opsplit[0])
value=int(opsplit[1])
else:
b=int(dsplit[1])
value=0
print "Generated number: "
print generateNumber(b,a,addorsub,value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment