python 3.6。给予语法错误

问题描述:

invalid syntaxpython 3.6。给予语法错误

high = 100 
low = 0 
print('Please think of a number between 0 and 100!') 
while True :  
    middle = (high + low) // 2 
    print('Is your secret number ' + str(middle)) 
    ans = 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 ans == 'h' : 
    high = ans 
    print('Is your secret number' + str(middle)) 
    elif ans == 'l' : 
    low = ans 
    print('Is your secret number' + str(middle) 
    elif ans == 'c' : 
    break 
print('your secret num is' + str(middle)) 

什么是错误的代码? 问题是 Exercise: guess my number

+0

你想让人们做你的考试考试吗? –

+0

您可以以代码格式发布错误消息。 – zhenguoli

high = 100 
low = 0 
print('Please think of a number between 0 and 100!') 
while True: 
    middle = (high + low) // 2 
    print('Is your secret number ' + str(middle)) 
    ans = 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.") 
    print(ans) 
    if ans == 'h': 
     high = middle 
     print('Is your secret number ' + str(middle)) 
    elif ans == 'l': 
     low = middle 
     print('Is your secret number ' + str(middle)) # This line lacks of ')' in your code. 
    elif ans == 'c': 
     break 

print('your secret num is ' + str(middle)) 

ans该不能被分配给highlow。它是middle将被分配到highlow