如何在python中创建可编辑的故事?

如何在python中创建可编辑的故事?,python,anaconda,python-3.6,Python,Anaconda,Python 3.6,您好,我想了解用python替换故事中单词的基本知识。 到目前为止,我有下面的代码。我在经营spyder 从用户处收集名称 关于用户的故事 我的程序只运行,不做任何其他事情。这称为字符串连接。在这种情况下,您可以只使用“+”符号 name = input("What is your name?") print("Hi, " + name + " nice to meet you." 在更复杂的情况下,您可能希望执行字符串插值-即获取固定字符串并插入值,如下所示: name = input("W

您好,我想了解用python替换故事中单词的基本知识。 到目前为止,我有下面的代码。我在经营spyder

从用户处收集名称 关于用户的故事
我的程序只运行,不做任何其他事情。

这称为字符串连接。在这种情况下,您可以只使用“+”符号

name = input("What is your name?")
print("Hi, " + name + " nice to meet you."
在更复杂的情况下,您可能希望执行字符串插值-即获取固定字符串并插入值,如下所示:

name = input("What is your name?")
birthsign = input("What is your birthsign?")
race = input("What is your race?")
father = input("Who was your father?")

#%s = insert string - we then pass the variables to insert in order of use
storyString = "Welcome %s son of %s of the sign %s and race %s. You have travelled far." % (name, father, birthsign, race)

print(storyString)

我切换到原始输入以确保得到字符串,然后在最后将结果连接成字符串。你想做的就是这样吗

def Travsnguard():
    print ("Welcome to Travsngaurd!")
    relative = input("Enter a type of relative: ")
    name = input("Enter a name: ")
    verb = input("Enter an 'ing' verb: " )
    adjective = input("Enter an adjective: ")
    noun = input("Enter a noun: ")
    print ("Hello,", name, "your journey starts now!")
    print ("You are here with your " + adjective + " " + relative + " raul. and you\
are going to go " + verb + ". You are going to use your " + noun + ".")
Travsnguard()

哇,你们反应真快谢谢你们的帮助
raw_input
在python 3中没有定义(注意,问题被标记为python 3.6)。这很尴尬,谢谢。这帮助了很多,但raw_input()函数我认为我不能在3.6中使用,它只允许我使用input()函数。我现在确实让它看起来更好了。我编辑为只使用普通输入,我需要切换到python 3,这样我就不会有这些问题。def Travsnguard():print(“欢迎使用Travsngaurd!”)relative=input(“输入一种相对类型:”)name=input(“输入名称:”)verb=input(“输入一个‘ing’动词:”)形容词=input(“输入一个形容词:”)名词=输入(“输入一个名词:”)打印(“你好,”,名字,“你的旅程现在开始!”)打印(“你带着“+形容词+”+“+亲戚+”+”来到这里,你将要去“+动词+”。你将要使用“+名词+”)Travsnguard()真是个愚蠢的问题,但你确实调用了
Travsnguard()
在代码末尾,对吗?
def Travsnguard():
    print ("Welcome to Travsngaurd!")
    relative = input("Enter a type of relative: ")
    name = input("Enter a name: ")
    verb = input("Enter an 'ing' verb: " )
    adjective = input("Enter an adjective: ")
    noun = input("Enter a noun: ")
    print ("Hello,", name, "your journey starts now!")
    print ("You are here with your " + adjective + " " + relative + " raul. and you\
are going to go " + verb + ". You are going to use your " + noun + ".")
Travsnguard()