#!/bin/python3 import random as rd import math as m import argparse as ap parser = ap.ArgumentParser() parser.add_argument('-s', help = "Number of sides of your Würfel. If not specified, you will be asked.") parser.add_argument('-l', default=1, help = "lowest number. Defaults to 1 if not specified.") parser.add_argument('-r', default=1, help = "Number of repetitions") parser.add_argument('-d', help = "number of repetitions with forced different output. Overwrites the -r flag.") parser.add_argument('-c', action = 'store_true', help = "Customise the sides of your Würfel. Overwrites the l-flag.") args = parser.parse_args() def recursive_Würfel(a, b, c): current_throw = int(m.floor(rd.uniform(b, c))) if a > 1: Ergebnisliste = recursive_Würfel(a-1, b, c-1) for i in range(a-1): if Ergebnisliste[i] >= current_throw: Ergebnisliste[i] = Ergebnisliste[i]+1 Ergebnisliste.append(current_throw) return Ergebnisliste else: return [current_throw] def lookup_ergebnisse(c, Ergebnisse, Seitenliste): if c: Würfe = [] for i in Ergebnisse: Würfe.append(Seitenliste[i]) return Würfe else: return Ergebnisse if args.s: n = int(args.s) else: n = int(input('how many sides du you wish your Würfel to have?')) b = int(args.l) Seitenliste = [] if args.c: for i in range(n): Seitenliste.append(input("Seite {}:".format(i))) b = 0 c = b+n if args.d: d = int(args.d) if d > n: print('ERROR: A', n, '-sided Würfel can only have', n, 'different outputs') else: Ergebnisse = lookup_ergebnisse(args.c, recursive_Würfel(d, b, c), Seitenliste) print(Ergebnisse) else: Ergebnisse = [] for i in range(int(args.r)): number = rd.uniform(b, c) Ergebnisse.append(int(m.floor(number))) print(lookup_ergebnisse(args.c, Ergebnisse, Seitenliste))