#1
14.03.2017 um 09:47 UhrKleiner Fehler hier:
In Zeile 9 sollte es
Python-Code
heißen
In Zeile 9 sollte es
start_x = ende_x/(2*platte)
heißen
Python :: Aufgabe #147 :: Lösung #1
import random
random.seed()
anzahl = 0
def bewegung():
global anzahl
if (ende_x/platte)%2 == 0:
start_x = ende_x/platte
else:
start_x = (ende_x+platte)/2
start_y = 0.0
while True:
schritt = random.randint(1,8)
if schritt == 1:
start_x -= platte
start_y += platte
elif schritt == 2:
start_y += platte
elif schritt == 3:
start_x += platte
start_y += platte
elif schritt == 4:
start_x -= platte
elif schritt == 5:
start_x += platte
elif schritt == 6:
start_x -= platte
start_y -= platte
elif schritt == 7:
start_y -= platte
elif schritt == 8:
start_x += platte
start_y -= platte
if start_x <= 0 or start_x >= ende_x or start_y < 0:
break
elif start_y == ende_y:
anzahl += 1
break
while True:
ende_x = float(input("Breite Tunnel: "))
ende_y = float(input("Länge Tunnel: "))
platte = float(input("Länge quadratische Platte: "))
if ende_x%platte == 0.0 and ende_y%platte == 0.0:
durchlauf = int(input("Anzahl Durchläufe: "))
for i in range(durchlauf):
bewegung()
break
else:
print("Falsche Eingabe! Platte muss Teiler von Breite und Länge des Tunnels sein!")
print("Die Wahrscheinlichkeit bei",durchlauf,"Versuchen den Tunnel unbeschadet zu überqueren beträgt:",\
100*anzahl/durchlauf,"%")Kommentare:
jigga
Punkte: 4260
73 Lösungen
7 Kommentare
start_x = ende_x/(2*platte)