Re: [Tutor] Whle Loop to run again.

2005-05-19 Thread Ricardo Catalinas Jimenez
0n Thu, May 19, 2005 at 02:50:16PM +, . , wrote:
 Hi,
 
 I want the program to run again when i input 'run' But, It doesn't...
 
 thanks.
 
 ---
 import random
 
 raw_input(Flip a coin!)
 
 head = 0
 tail = 0
 run = 
 
 while (head + tail)  100:
 coin = random.randrange(2)
 if coin == 0:
 head += 1
 
 elif coin == 1:
 tail += 1
 
 elif run == run:
 continue
 
 elif run == ex1t:
 print ex1t
 break
 
 else:
 print Error
 
 print \n, head, heads,, tail, tails out of 100.
 
 
 
 
 run = raw_input(\n'run' again or 'exit' )
 
 ex1t = raw_input(\nPress the enter key to exit.)

--- code ---

import random

raw_input(Flip a coin!)

head = 0
tail = 0
run = 

while True:
while (head + tail)  100:
coin = random.randrange(2)
if coin == 0: 
head += 1
   
elif coin == 1:
tail += 1

print \n, head, heads,, tail, tails out of 100.
head, tail = 0, 0


run = raw_input(\n'run' again or 'exit' )
if run == exit:
break

elif run == run:
continue

else:
print Error


ex1t = raw_input(\nPress the enter key to exit.)

--- end code ---

Sorry, I changed your indentation by tabs characters.
-- 
Ricardo Catalinas JimenezMadrid, Spain.
th1nk3r(at)server01(dot)org  http://www.server01.org
GnuPG Key fingerprint = 662C EBF7 9220 0F14 C644  F90B DC3E A163 7F8D CDAE
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Whle Loop to run again.

2005-05-19 Thread Alan G
 I want the program to run again when i input 'run' But, It
doesn't...

You need another loop, or to ask for input inside the loop.
If you always want 100 iterations then prompt for another
hundred structure it like:

run = raw_input('run or exit? ')
while run = 'run':
   for n in range(100):
  coin = random.randrange(2)
  if coin == 1: heads += 1
  else coin == 2: tails += 1
   run = raw_input('run or exit? ')


But if you want to check after every coin toss (as your if/elif chain
code
seems to suggest) but with a maximum of 100 iterations, try it this
way:

heads,tails = 0,0
while heads+tails  100:
 coin = random.randrange(2)
 if coin == 1: heads += 1
 else coin == 2: tails += 1

 run = raw_input('run or exit? ')
 if run = 'run': continue
 else: break

HTH,

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor