Created
September 30, 2012 10:25
-
-
Save anonymous/3806407 to your computer and use it in GitHub Desktop.
dailyprogrammer#102 solved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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