I wrote a script that gives a "generalized" function of an arbitrary dice. Is this any good? How can it improve so to make it cleaner?
import random
def roll(die):
number = random.randint(0,len(die)-1)
b = die[number]
return b
Die1 = [1,2,3,4]
Die2 = [1,2,3,4,5,6] #num lists
def inptchacc():
ending_conditions = ['stop','Stop','quit','Quit']
end = False
inpu = input('what number would you like to add to the new face of the Die? (to end the die please type "stop or Stop or quit or Quit to finish the DIE" )')
while end == False:
if not(inpu in ending_conditions):
try:
retr = int(inpu)
return retr
except:
string = 'invalid input please try again'
inpu = input('invalid input please try again ')
else:
stop = 'stop'
return stop
def deeper(IDie):
list = []
Adding = True
while Adding:
print('The Die ' + IDie + ' is currently ' + str(list) )
toadd = inptchacc()
if toadd != 'stop':
list.append(toadd)
else:
Adding = False
return list
def chance_overlap(Die1,Die2):
highnumber = 1000
counter = 0
for n in range(highnumber):
x = roll(Die1)
y = roll(Die2)
if x == y:
counter += 1
chance = counter/highnumber
return chance
chance = chance_overlap(Die1,Die2)
print(chance)
Doing = True
while Doing:
try:
IDie1 = deeper('IDie1')
IDie2 = deeper('IDie1')
chance2 = chance_overlap(IDie1,IDie2)
Doing = False
except:
print ('incompatible options selected returning....... ')
print(chance2)

