51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

这段代码为什么在Jupyter Notebook上运行正常,但在新的Python文件上不起作用?

英文:

Why does this code work on jupyter notebook but don´t work on a new python file?

问题 {#heading}

为什么在.py(Python)格式上运行时,该代码显示缩进错误,但在.ipynb(Jupyter Notebook)上运行时可以顺利运行?

这是我在新的Python文件上使用代码时显示错误的图像

这是我在新的Jupyter Notebook文件上运行代码时的图像

我在互联网上搜索了关于缩进问题的所有信息,并且过去一天都在学习使用制表符和空格进行缩进时出现的问题,但对我来说似乎不是制表符和空格的问题,因为在Jupyter Notebook中可以正常工作。我已经激活了在我的代码上显示所有空白字符的选项,以更好地确定问题的所在,但是......我一头雾水。

我是编程新手,正在学习很多东西,您能帮助我吗? 英文:

Why does that code shows identation error when on a .py (Python) format and it runs smoothly when in a .ipynb (Jupiter Notebook)?

Here is the image showing the error when I´m using the code on a new Python file

Here is the image when I run the code a new Jupiter Notebook file

I searched for identation problems all over the internet and I spent the last day only studying about the problems that arise from using tab and space for identation but it really doesn´t appear for me that it´s a tab and space problem since it work inside Jupiter Notebook. I activated the option to show all whitespace on my code so I can better pin down where is the problem but...I´m clueless.

I´m new to programming and learning a lot so can you send me some help on this?

答案1 {#1}

得分: 0

在第一张照片(Python文件)中,看起来你还没有保存文件,也许这可能会导致错误。 英文:

In the first photo (Python file), looks like you haven't saved the file and maybe this can cause the error.


赞(1)
未经允许不得转载:工具盒子 » 这段代码为什么在Jupyter Notebook上运行正常,但在新的Python文件上不起作用?