【问题标题】:python 3.6. Giving syntax error蟒蛇 3.6。给出语法错误
【发布时间】:2017-06-16 07:33:44
【问题描述】:

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))

代码有什么问题? 问题是

【问题讨论】:

  • 你想让别人做你的考试吗?
  • 您可以将错误信息以code格式贴出来。

标签: python-3.x


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    • 2018-08-24
    • 2018-05-10
    • 2016-10-17
    相关资源
    最近更新 更多