字符输入不停止程序

时间:2017-02-17 09:12:13

标签: python python-3.x input

我是Python的新手,在使用以下内容时遇到错误:

name = input("Would you please enter your name: ")
age = int(input("Would you please enter your age: "))
year = str((2017 - age)+100)
print("Your name is " + name + "and you will turn 100 years old in the year "  + year)

当我从命令提示符(Windows 10)打开Python 3.5.3,并从记事本中复制并粘贴此代码时,第一行显示为:

>>>> name = input("Would you please enter your name: ")
Would you please enter your name: age = int(input("Would you please enter 
your age: "))

如何规避这个问题?从我所看到的,该程序应该在遇到“input”之后中断。

作为参考,我开始解决http://www.practicepython.org/exercise/2014/01/29/01-character-input.html

中的问题1

1 个答案:

答案 0 :(得分:0)

在Python中,交互模式行在每个换行符处执行,因此在您的示例中为Select d.MinPrice,d.MaxPrice,d.ClosingPrice, d.PreviousClosingPrice from StockPriceDetl d inner join Stock st on d.StockId=st.Id inner join StockPriceMast sm on d.MastId = sm.Id where st.StockSymbol='NABIL' and sm.TranDate between '2001-01-01'and'2002-01-01' 分配了字符串name的值。

如果要将完整代码复制到交互式提示中并使其仅在所有行之后执行,则在复制文本之前必须add ;\到每行的末尾。 'age = int(input("Would you please enter your age: "))'显示分配已结束,但;表示行继续,因此代码不会立即执行:

\