Python中的raw_input用法

2024-04-26 01:35:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用这个python脚本时遇到了很多麻烦:

import time
print "Loading Interface"
time.sleep(0.5)
print "Loaded Interface"
time.sleep(1)
question_one = raw_input = "Request: Enter your name: "
question_two = raw_input = "Request: Enter your password: "
time.sleep(1)
print "Searching for %s with the password %s in our database." % (question_one, question_two)

有人能告诉我我做错了什么吗?你知道吗


Tags: import脚本inputyourrawtimerequestsleep
3条回答

首先,不清楚你在问什么。另外,当程序没有真正加载的时候,你有故意的延迟。。。不知道你为什么要这么做。实际上你并没有调用原始输入,你只是给它分配了一个变量。相反,请尝试以下方法:

question_one=raw_input("Request: enter your name: ")

这个^^^实际上会问用户一个问题。你知道吗

raw_input是一个函数,所以您必须调用它,而不仅仅是给它赋值。你知道吗

试试这个:

question_one = raw_input("Request: Enter your name: ")

我相信你的意思是,问题在于原始导入提示不起作用。这是因为raw\u import是一个函数,(可选)参数可以是import提示符(请参见:https://docs.python.org/2/library/functions.html#raw_input

也就是说,这应该起作用:

import time
print "Loading Interface"
time.sleep(0.5)
print "Loaded Interface"
time.sleep(1)
question_one = raw_input ("Request: Enter your name: ")
question_two = raw_input ("Request: Enter your password: ")
time.sleep(1)
print "Searching for %s with the password %s in our database." % (question_one, question_two)

相关问题 更多 >

    热门问题