无法使Madlibs的打印工作,如何修复?

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

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

huangapple
  • 本文由 发表于 2023年6月29日 06:09:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576992.html
匿名

发表评论

匿名网友

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

确定