2017-06-16 85 views
-4

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

回答

0
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