10 步:太好了,现在我们需要在输入有效时停止循环,并在输入无效时告诉用户。

我们可以在适当的时候使用break来退出循环,在这种情况下是在try块的末尾。

  • 并将Break拖到try块的最后一行。
  • 如果我们确实收到错误,让我们让用户知道!从except块中删除print( "Cannot · divide · by · 0" )
  • 在图形中,转到.将Say拖入except 。将文本更改为"Enter a number!"

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)