猜数程序,提交时提示错误,但是自测时时对的
在自学6.00.1x 计算机科学和Python编程导论的时候,有一个练习题是猜数程序。然后我的代码是这样的
程序代码: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) 但是在提交的时候,测试出了这么个问题。但是我自己拿91作为猜测数,运行了程序又是对的。求大神指教











会继续努力