# Modul random importieren import random # Zufallszahlengenerator initialisieren random.seed() # erzeugt eine Koordinate im Bereich von -1 bis 1 def koordinate(): # random.random() erzeugt Zufallszahl im Bereich von 0 bis 1 test = random.random() if test > 0.5: return random.random() else: return -random.random() while True: print() print("Monte Carlo") print("***********") print() p = int(input("Anzahl Punkte: ")) t = 0 for i in range(p): x = koordinate() y = koordinate() if (x**2+y**2)**(1/2) < 1: t += 1 print("Näherungswert für pi:",4*t/p) print() if input("Nochmal? (J/N) ") == "N": break