Skip to main content
7 of 7
Updated for new character count (300)
Rees
  • 111
  • 1
  • 3

Python 2.7 334 335 327 314 300 Characters (My first time golfing)

(335) Forgot to escape newline.

(327) Removed redundant 100 for randint. Comparison of first character of response, instead of whole string.

(314) Updated printing who won.

(300) Changed when player was player 1: changed guessing of the number as computer

from random import*
i=input
s="Enter number:"
p=i("Player 1/2:")-1
h=100
N=(i(s),randint(1,h))[p]
b=l=0
for _ in[0]*5:
 exec("g=(h+l)/2;r=raw_input('Guessing '+`g`+':')[0];exec('h=g','l=g')[r=='l'];b=r=='c'","g=i(s);b=g==N;print(('higher','lower')[N<g],'correct')[b]")[p]
 if b:break
print 1+b,"won"
Rees
  • 111
  • 1
  • 3