#2
莫珞lili2016-09-09 11:49
|
程序代码:
low = 0
high = 100
ans = (low + high)/2
print 'Please thinkof a number between 0 and 100!'
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
while check != 'c':
if check =='h':
high =ans
elif check == 'l':
low = ans
else:
print('Sorry, I did not understand your input.')
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
ans = (low + high)/2
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
if check == 'c':
print 'Game over. Your segggcret number was: '+str(ans)
但是在提交的时候,测试出了这么个问题。high = 100
ans = (low + high)/2
print 'Please thinkof a number between 0 and 100!'
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
while check != 'c':
if check =='h':
high =ans
elif check == 'l':
low = ans
else:
print('Sorry, I did not understand your input.')
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
ans = (low + high)/2
print 'Is your secret number ' + str(ans) + '?'
check = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
if check == 'c':
print 'Game over. Your segggcret number was: '+str(ans)
只有本站会员才能查看附件,请 登录
但是我自己拿91作为猜测数,运行了程序又是对的。求大神指教