英文:
Cannot get a Madlibs print to work, how to fix it?
问题
无法使打印函数输出Madlibs,更具体地说,VS Code上的默认播放按钮不会输出它,只有调试功能会输出。我在YouTube上看了一堂来自Freecodecamp的教程,第一次尝试时,不出所料,它起作用了。我添加了一点内容,并确信它会起作用,但什么也没发生,输出显示语法错误,我不明白,我认为从第1行开始,这是代码:
adjective = input("输入形容词")
verb = input("输入动词")
madlib = f"I went for a -{verb}- and seen a -{adjective}- dog"
print(madlib)
我得到的错误是:
SyntaxError: invalid syntax
>>> & C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
File "<stdin>", line 1
& C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
^
我尝试的第一件事是重新调整代码,例如删除一个形容词和一个动词,以简化并查看出了什么问题,但什么也没发生,所以我把它们添加回去,我刚刚做的另一件事是在VSCode中进行调试,它起作用了,但我想知道为什么默认的播放按钮没有按我想要的方式工作。
英文:
Cannot get the print function to print out the Madlibs, more specifically the default play button on vs code doesn't output it, only the debug feature, I was watching a tutorial from Freecodecamp from Youtube and the first time I tried it, no surprise it worked. Added a little more and positive that it would work, but nothing happened, output says incorrect syntax which I don't get, I believe it starts from line 1, here's the code.
adjective = input("Input adjective")
verb = input("Input verb")
madlib = f"I went for a -{verb}- and seen a -{adjective}- dog"
print(madlib)
The error I got was this
SyntaxError: invalid syntax
>>> & C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
File "<stdin>", line 1
& C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
^
First thing I have tried is reworking the code, such as removing one adjective and one verb, to simplify and see if I could understand what went wrong, and nothing happened so I added them back, another thing I did just now was put it through debug in VSCode, it worked, but I want to know why the default play button isn't doing what I want it to do.
答案1
得分: 0
错误看起来像你正在尝试从Python shell内部运行该文件。尝试在Powershell中运行该命令。命令提示符也可以,但你需要删除&
:C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
。
英文:
The error looks like you are trying to run the file from inside the Python shell. Try to run the command inside Powershell. Command Prompt would also work, but you'd have to remove the &
: C:/Python311/python.exe c:/Users/perso/OneDrive/Documents/GitHub/Madlibs/game.py
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论