Python缩进之谜

编程入门 行业动态 更新时间:2024-10-27 20:36:50
本文介绍了Python缩进之谜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么会出现以下错误?最后一个print语句不应成为while循环的一部分.

Why am I getting the following error? The last print statement should not be a part of the while loop.

>>> while n>= 0: ... n = n-1 ... print(n) ... print ("TO A!!") File "<stdin>", line 4 print ("TO A!!") ^ SyntaxError: invalid syntax

推荐答案

在while循环后,您需要按 enter 退出循环

You need to press enter after your while loop to exit from the loop

>>> n = 3 >>> while n>=0: ... n = n-1 ... print (n) ... # Press enter here 2 1 0 -1 >>> print ("To A!!") To A!!

注意:-...表示您仍在while块中

Note:- ... implies that you are still in the while block

更多推荐

Python缩进之谜

本文发布于:2023-11-08 18:50:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570144.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:之谜   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!