Python 升华文本3不接受输入()

Python 升华文本3不接受输入(),python,sublimetext3,Python,Sublimetext3,代码在pythonshell中按预期工作,通过idle启动。当通过sublime文本运行该文件时,它只将please enter your price:打印到控制台,而不在提交我的输入后运行剩余的代码。在控制台上按enter键只会创建新行。在pythonshell中运行代码时,其余代码在将int提交到tip计算器后执行 def calculateit(): price = input("please enter your price: ") tip = int(price)

代码在pythonshell中按预期工作,通过idle启动。当通过sublime文本运行该文件时,它只将please enter your price:打印到控制台,而不在提交我的输入后运行剩余的代码。在控制台上按enter键只会创建新行。在pythonshell中运行代码时,其余代码在将int提交到tip计算器后执行

def calculateit():
     price = input("please enter your price: ")
     tip = int(price) * 0.25
     final = int(tip) + int(price)
     print ("since the price of your meal is " + str(price) + " your tip is " + str(tip))
     print ("the total cost of your meal is " + str(final))

calculateit()

在Sublime中执行代码时,无法捕获输入。更严格地说,控制台连接到stderr和stdout,而不是stdin。因此,不可能直接从Sublime内部运行交互式程序

然而,在看到您的代码后,出现了一个问题-为什么不在第一次使用用户输入法转换price变量,这样您就不需要多次将它从str转换为int,反之亦然。为了让您明白这一点,请参阅下面的代码,这与我认为的方法完全相同,但更聪明

def calculateit():
    price = int(input("please enter your price: "))
    tip = price * 0.25
    final = tip + price
    print (f"since the price of your meal is {price} your tip is {tip}" )
    print (f"the total cost of your meal is {final}" )

calculateit()

升华上次检查时不接受用户输入请在发布前尝试搜索问题。可能的副本好的,谢谢。我只需要在空闲状态下运行它。你问题的答案主要是因为我不太清楚。“我在一行一行地想这个问题。”“罗伯顿,如果答案对你有帮助的话,请记下来。”。谢谢