from math import sqrt
import random
bonus = 1
iterations = 10000000
def d(x): return random.randint(1,x)
results = [0]*(10-bonus)
for i in range(iterations):
target = 10
tries = 1
success = False
while not success:
success = (d(10)+bonus>=target)
if success:
break
else:
tries+=1
target-=d(3)
results[tries-1]+=1
average = sum([results[i]*(i+1) for i in range(len(results))])/iterations
deviation = sqrt(sum([results[i]*(i-average)**2 for i in range(len(results))])/(iterations-1))
print("Average: {:.3f}+-{:.3f}".format(average,deviation))
print("Number of Tries | "+" | ".join([str(x).rjust(6) for x in range(1,1+len(results))]))
print("Chance | "+" | ".join([str(round(x/iterations*100,3)).rjust(6) for x in results]))
ZnJvbSBtYXRoIGltcG9ydCBzcXJ0CmltcG9ydCByYW5kb20KIApib251cyA9IDEKaXRlcmF0aW9ucyA9IDEwMDAwMDAwCiAKZGVmIGQoeCk6IHJldHVybiByYW5kb20ucmFuZGludCgxLHgpCiAKcmVzdWx0cyA9IFswXSooMTAtYm9udXMpCmZvciBpIGluIHJhbmdlKGl0ZXJhdGlvbnMpOgogICAgdGFyZ2V0ID0gMTAKICAgIHRyaWVzID0gMQogICAgc3VjY2VzcyA9IEZhbHNlCiAgICB3aGlsZSBub3Qgc3VjY2VzczoKICAgICAgICBzdWNjZXNzID0gKGQoMTApK2JvbnVzPj10YXJnZXQpCiAgICAgICAgaWYgc3VjY2VzczoKICAgICAgICAgICAgYnJlYWsKICAgICAgICBlbHNlOgogICAgICAgICAgICB0cmllcys9MQogICAgICAgICAgICB0YXJnZXQtPWQoMykKICAgIHJlc3VsdHNbdHJpZXMtMV0rPTEKCmF2ZXJhZ2UgPSBzdW0oW3Jlc3VsdHNbaV0qKGkrMSkgZm9yIGkgaW4gcmFuZ2UobGVuKHJlc3VsdHMpKV0pL2l0ZXJhdGlvbnMKZGV2aWF0aW9uID0gc3FydChzdW0oW3Jlc3VsdHNbaV0qKGktYXZlcmFnZSkqKjIgZm9yIGkgaW4gcmFuZ2UobGVuKHJlc3VsdHMpKV0pLyhpdGVyYXRpb25z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