Python无法运行,我不知道问题是什么。

huangapple go评论56阅读模式
英文:

Python doesn't run and I don't know what is the problem

问题

it just shows my file path in the terminal window when I click Run. Please help, I'm new to this sorry.

我点击运行时,在终端窗口中只显示我的文件路径。请帮帮我,我是新手,对此很抱歉。

I tried to search for tutorials on youtube but I don't know what to search for this kind of problem
I also tried to check my Code runner extension

我尝试在YouTube上搜索教程,但我不知道要搜索这种问题的内容。我还尝试了检查我的Code Runner扩展。

英文:

it just shows my file path in the terminal window when I click Run. Please help, I'm new to this sorry.

I tried to search for tutorials on youtube but I don't know what to search for this kind of problem
I also tried to check my Code runner extension

答案1

得分: 1

Python不会在启动时自动运行main()函数,您需要自己调用它。因此,您的程序目前只由函数组成,没有任何东西可运行,实际上可以正常运行。

您可能希望添加以下代码以获得您期望的行为:

if __name__ == "__main__":
    main()

这将在从命令行启动程序时调用main函数。

英文:

Python doesn't automatically runs main() when started, you need to call it yourself. Therefore, your program is currently only made of functions, and there's nothing to run, it actually runs properly.

You may want to add this code for the behaviour you're expecting:

if __name__ == "__main__":
    main()

This will call the main function when the program is started from the command line.

答案2

得分: 0

你已经定义了主函数,但你从未调用它。

在你的代码末尾添加main()。

英文:

You defined the main function, but you never call it.

add main() to the end of your code.

答案3

得分: 0

Python程序在运行时不会自动调用任何函数。您必须调用函数才能运行它。要运行main()函数,请像下面这样调用它:

main()

或者,如果您想在程序运行时从命令行运行任何函数,您必须使用以下代码:

if __name__ == "__main__":
    main()  # 调用您的函数
英文:

Python won’t call any function automatically when the program is run. You have to call the function for it to run. To run the main() function, call it like below:

main()

Alternatively, if you want to run any function from the command line when the program is run, you have to use the following code:

if __name__ == "__main__":
    main() #Call your function

huangapple
  • 本文由 发表于 2023年7月13日 16:58:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定