为什么即使我要求输入,此脚本也会立即关闭?

时间:2014-06-02 17:11:35

标签: python

我无法使用此代码在python中获取输出。

import random
die1=random.randrange(5)
die2=random.randrange(5)
total=die1+die2
input=("\nPress the ENTER key to exit.")

黑色窗口在打开时立即关闭

2 个答案:

答案 0 :(得分:3)

没有打电话 input();您正在字符串分配给名称input

删除 =

input("\nPress the ENTER key to exit.")

答案 1 :(得分:0)

在这里,您要将input分配给元组("\nPress the ENTER key to exit.")

相反,将等号移至之前 input

inp = input("\nPress the ENTER key to exit.")

以下是您编辑的代码:

import random
die1=random.randrange(5)
die2=random.randrange(5)
total=die1+die2
inp = input("\nPress the ENTER key to exit.")

现在您的输入将存储在变量inp

相关问题