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

Python 2.7 334 335 327 314314 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
execN=("N=ii(s)","N=randintrandint(1,h)")[p]
b=l=0
for _ in[0]*5:
 exec("g=(h+l)/2;r=raw_input('Guessing '+`g`+':');exec([0];exec('h=g','l=g')[r[0]=='l'],'b=1')[r[0]=='c']"[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"

Python 2.7 334 335 327 314 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.

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

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"
From got cut off fron import
Source Link
Rees
  • 111
  • 1
  • 3

Python 2.7 334 335 327 314 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.

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

Python 2.7 334 335 327 314 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.

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

Python 2.7 334 335 327 314 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.

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

Python 2.7 334 335 327 314 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 printing.

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

Python 2.7 334 335 327 314 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 who won printing.

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

Python 2.7 334 335 327 314 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.

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