#!/usr/bin/python3 import random N = 10 max_steps = 99999999 repeats = 10000 def go(): poloha = 0 for i in range(max_steps): krok = random.choice([-1,1]) poloha = max(0, poloha + krok) # hranice na nule #poloha = abs(poloha + krok) # pruchod nulou if poloha == N: return i total_steps = 0 for _ in range(repeats): total_steps += go() print(f"Průměrně jsem do polohy {N} došel za {total_steps/repeats} kroků.")