[Tutor] [Fwd: guess]
Kent Johnson
kent37 at tds.net
Wed Oct 4 12:02:58 CEST 2006
Forwarding to the list
-------- Original Message --------
Subject: guess
Date: Tue, 03 Oct 2006 18:12:08 -0600
From: mike viceano <ph34r_th3_d4rkn3s at hotmail.com>
To: kent37 at tds.net
hey i added another guessing feature that shuld guess the number in the
most
effective way
but i keep getting into endless loops thought you might want it
any help with the loops would be great
def number(number):
ran=input("range >")
ran=ran+1
from random import randrange
guessed=[]
guess=randrange(ran)
print guess
guessed.append(guess)
guesses=1
guessed=[]
while guess !=number:
guess=randrange(ran)
if guess not in guessed:
guessed.append(guess)
guesses=guesses+1
print guess
print"i got the number",number,"in",guesses,"guesses"
def num(number):
r=input("range >")
ran=range(r+1)
guess=r/2
print guess
guesses=1
while guess!=number:
if guess < number:
guess= ((r-guess)/2)+guess
print guess
guesses=guesses+1
elif guess > number:
guess= ((r-guess)/2)-guess
print guess
guesses=guesses+1
print "i got the number",number,"in",guesses,"guesses"
_________________________________________________________________
Be seen and heard with Windows Live Messenger and Microsoft LifeCams
http://clk.atdmt.com/MSN/go/msnnkwme0020000001msn/direct/01/?href=http://www.microsoft.com/hardware/digitalcommunication/default.mspx?locale=en-us&source=hmtagline
More information about the Tutor
mailing list