为什么 print() 函数不能打印我在 Windows 中要求的内容?
只是为了好玩,我正在 Python 3.2 中构建一个非常简单的基于文本的游戏。我的开发计算机运行的是 Windows 7,并且我使用 PyScripter IDE 来开发此游戏。
我遇到了 print()
函数无法正确打印字符串的小问题。当您开始游戏时,程序会显示一个小菜单,其中包含 3 个选项:登录
、注册
和退出
。当我去注册时,程序从我创建的名为 Character
的自定义类中创建一个对象。该角色接收一个 name
变量,然后使用该 name 变量打印出一条小消息。这是我必须执行此操作的代码:
user_choice = int(input("Please select a command: "))
if user_choice == 1:
print("Sorry, this function isn't currently implemented.",
"Please check back later.\n")
elif user_choice == 2:
hero_name = input("Please choose a name for yourself, adventurer: ")
hero = Character(hero_name)
print("I see, so your name is", hero.name + "... Very well. We shall begin your journey immediately!\n")
代码应该正常工作,当我在 PyScripter 中运行程序时,我会得到一个很好的输出:
我明白了,所以你的名字是(我选择的名字)...很好。我们将立即开始您的旅程!
但是,当我从 cmd 提示符运行该程序时,我得到:
...很好。我们将立即开始您的旅程!
我在这里做错了什么吗?或者这是 Windows 上的一个错误?
Just for fun, I'm building a very simple text-based game in Python 3.2. My development machine is running Windows 7, and I'm using the PyScripter IDE to develop this game.
I'm running into a slight problem with the print()
function not printing a string out correctly. When you begin the game, the program displays a small menu with 3 choices: Login
, Register
, and Exit
. When I go to register, the program creates an object from a custom class I made called Character
. The character takes in a name
variable, and then prints out a small message using the name variable. Here's the code that I have to do that:
user_choice = int(input("Please select a command: "))
if user_choice == 1:
print("Sorry, this function isn't currently implemented.",
"Please check back later.\n")
elif user_choice == 2:
hero_name = input("Please choose a name for yourself, adventurer: ")
hero = Character(hero_name)
print("I see, so your name is", hero.name + "... Very well. We shall begin your journey immediately!\n")
The code should work properly, and when I run the program in PyScripter, I get a nice output:
I see, so your name is (the name I chose)... Very well. We shall begin your journey immediately!
But, when I run the program from the cmd-prompt, I get:
... Very well. We shall begin your journey immediately!
Am I doing something wrong here? Or is this a fault on Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您的
print()
语句中有一个拼写错误:I believe there's a typo in your
print()
statement:以下内容在带有 Eric5 IDE 的 Python 3.2 中工作:
The following works in Python 3.2 with Eric5 IDE: