【问题标题】:Python input function keeps on taking input even after EOF?即使在EOF之后,Python输入函数也会继续输入?
【发布时间】:2017-01-20 17:30:47
【问题描述】:

我刚开始学习python,遇到一个错误,我不知道如何解决。 我刚刚写了一个代码,它只是要求用户输入一个数字,使用输入功能。

a=input("enter the number:")
print("The number you entered:")
print(a)

这个输出是

enter the number:101
4645
65465464564654654
54545445

enter image description here

它只是不去打印语句,它继续接受变量a的输入。请帮忙... 我正在使用pycharm编写代码。

【问题讨论】:

  • 这里工作正常,尝试从命令运行,例如python test.py
  • EOF 还是回车(即回车/回车)?还是在输入结束时按 ctrl+d?
  • @WayneWerner 在 Windows 上是 Ctrl+Z。
  • 我输入了 105 并按下回车,但它没有进入打印语句(第 2 行)
  • 它在 IDLE 上运行良好(逐行成功执行),但在 pycharm 中,它继续接受输入。

标签: python python-3.x


【解决方案1】:

不确定我的问题是否正确,但您可以尝试写作:

a = input("enter the number:")
print ("The number you entered:" , a)

并在 shell 中运行它。您将能够获得输出:

enter the number:101
The number you entered: 101

希望这会有所帮助!

【讨论】:

  • 我刚刚更新了 pycharm,它得到了修复。这是一个错误。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
相关资源
最近更新 更多