[GERMAN] "ziegenproblem"
Nick Mathewson
QnickQm at alum.mit.edu
Thu Mar 7 14:23:59 EST 2002
In article <mailman.1015525513.28986.python-list at python.org>,
stefan antoni wrote:
[...]
> i want to write this basic code in python:
> http://www.google.de/search?q=3Dcache:Uugc3CH9SOQC:home.spektracom.de/ellri=
> ch/Ziegen.htm+ziegenproblem+basic+programm&hl=3Dde
Sadly, I don't know enough German to understand what is
going on, but given the original basic:
140 CLS : RANDOMIZE TIMER: PRINT
150 PRINT "Von 2000 Wechseln waren ": PRINT
160 FOR i = 1 TO 10
170 r = 0: f = 0
180 FOR j = 1 TO 2000
190 a = INT(3 * RND + 1)
200 w1 = INT(3 * RND + 1)
210 m = INT(3 * RND + 1)
220 IF (m = a) OR (m = w1) THEN 210
230 w2 = 6 - m - w1
240 IF w2 = a THEN r = r + 1
250 IF w1 = a THEN f = f + 1
260 NEXT j
270 PRINT "richtig:"; r; "falsch:"; f
280 NEXT i
290 END
This is the most literal Python translation I could write:
import random
def rnd():
' returns one of (1,2,3) at random. '
return int(3*random.random() + 1)
print "\nVon 2000 Wechseln waren \n"
for i in range(1,11):
r = 0; f = 0
for j in xrange(1,2001):
a = rnd()
w1 = rnd()
m = rnd()
while m in (a, w1):
m = rnd()
w2 = 6 - m - w1
if w2 == a: r += 1
if w1 == a: f += 1
print "richtig: %s falsch: %s" % (r,f)
I'm-guessing-the-last-pair-is-true-or-false-but-darned-if-I-know-
what's-going-on-ly yrs,
--
Nick Mathewson <Q nick Q m at alum dot mit dot edu>
Remove Q's to respond. No spam.
More information about the Python-list
mailing list