print "This is a dating message that I am going to test, I want the user to be able to input their own answers."
print "I'd like for this message to work correctly, this is a dating message for Python"
print "Hi there, I think you're very cute and that's why I'm sending you this message"
print "I'm going to prompt you to see if you'd like to go on a date with me, type 'ok' to continue"
raw_input()
print "Type 'y' if you'd like to go out, or 'n' if you're not interested."
raw_input(y) = "Hooray I'm so happy to hear that! You should text me at 888-888-8888"
raw_input(n) = "Awww darnit, well best of luck to you!"
我非常擅长编程,我现在实际上在大学,但我只是很好奇我一直在努力分配特定的文本,如输入输入python中的变量,任何人都可以告诉我我做错了什么吗?
答案 0 :(得分:1)
raw_input
是一个返回用户答案的函数。
yesno = raw_input("Type 'y' if you'd like to go out, or 'n' if you're not interested.")
if yesno == 'y':
print "Hooray I'm so happy to hear that! You should text me at 888-888-8888"
else:
print "Awww darnit, well best of luck to you!"
答案 1 :(得分:1)
如果我能正确理解,你正在寻找将raw_input分配给某个变量。这将是解决问题的方法
age = raw_input("Enter your age: ")
print age
答案 2 :(得分:0)
努力学习编程。你想做什么?
您可以在控制台中使用此打印文本:
print "Hello World"
您可以使用它来提示用户并保存输入内容:
something = raw_input("Just type something? ")
在此之后,您将在/ something /变量中输入用户输入的字符串,您可以将其打印出来:
print something
这有帮助吗?
答案 3 :(得分:0)
您可以为字符串对象指定名称,如下所示:
var = "This is a text string"
现在每当我们使用var
时,它都会引用“这是一个文本字符串”。
print var
This is a text string
函数(仅命名代码块)返回对象。它可以是任何Python对象,包括文本字符串。然后我们可以在赋值中使用该函数调用:
reply = raw_input("Please type something: ")
无论用户输入什么, raw_input
都会返回。现在我们可以使用名称reply
来引用该字符串对象。
当然,我们可以将这些结合起来:
prompt = "Please type something: "
reply = raw_input(prompt)