解析时出现较高或较低的游戏意外EOF

时间:2019-06-10 05:05:43

标签: python

需要更高或更低游戏的帮助我认为问题与循环有关。有人告诉我添加一个except,但是我不知道在哪里添加

print('Welcome to higher or lower game')

input('press enter to start.\n')

import random
Max = 10
Min = 0

num = random.randint(1, 10)

print('your starting number is a ' + str(num))

while 'well done.\n' :

guess = input('higher (h) or lower (l).\n')

new_num = random.randint(1, 10)

print('your new number is a ' + str (new_num))

try :
   if new_num > num and guess == 'h':
    print('well done.\n')
   elif new_num < num and guess == 'l':
    print('well done.\n')
    break

  if num and guess == 'l' and new_num > num and guess:
   print('game over')
  elif num and guess == 'h' and new_num < num and guess:
   print('game over')
  else:
   print('game over you got a score of ' + str(score))  

2 个答案:

答案 0 :(得分:0)

您在except语句中没有try子句。除非您有finally子句,否则该子句是必需的。

答案 1 :(得分:0)

您真的不应该在那里有一个try语句。您可以将其取出,然后使用一些if和elif语句。

示例:

ChangePrice = (e, elem) => {
    this.setState(
        {
            NewAmount: (this.state.NewAmount || 0) + elem
        },
        () => {
            this.reorganiseLibrary();
        }
    )
}

据我了解,try语句主要用于错误处理。