2015-05-07 43 views
-1

我在询问用户的身体属性(头发颜色,眼睛颜色等)。语音标记中的打印变量

chooseCharacter = input("What character do you want to use? (%s or %s): " % (charOne, charTwo)) 
if chooseCharacter=="%s" % charOne: 

attributes=[] 

hair= input("what colour hair does %s have?" % (charOne)) 

build= input("what build is %s?" % (charOne)) 

eyes= input("what colour eyes does %s have?" % (charOne)) 

weaponOfChoice= input("what weapon is %s using?" % (charOne)) 

defence= input("what defence does %s use?" % (charOne)) 

("%s")=('hello %s. Am i right to say you have',hair,'right?. You should also be',build,'and have',eyes,'eyes.' % charOne) 

如何打印出说明?

你好(charOne)我是正确的说你(定义)的头发,(定义) 眼睛

+0

当你说“这是行不通的”,你得到了什么错误? – fixxxer

+0

如果您在运行时包含了当前正在获得的确切输出,将会有帮助 – OverloadUT

+0

要进行打印,请使用'print'。不奇怪'(“%s”)='。 –

回答

0

我不知道从何处取得("%s")=(...)。我从来没有见过这样的事情。确保您将您的代码与已知的良好代码进行比较。

最后一行应该是:

print 'hello %s. Am i right to say you have %s right?. You should also be %s and have %s eyes.' % (charOne, hair, build, eyes) 

或拆分成两行:

print 'hello %s. Am i right to say you have %s right?' % (charOne, hair) 
print 'You should also be %s and have %s eyes.' % (build, eyes) 
+0

谢谢你,并感谢社区。 –

0

首先可以肯定的“如果”后缩进是正确的。 然后,最后一行似乎是错误的。

这个例子将工作:

charOne="a" 
charTwo="b" 

chooseCharacter = input("What character do you want to use? (%s or %s): " % (charOne, charTwo)) 
if chooseCharacter=="%s" % charOne: 

    attributes = [] 

    hair= input("what colour hair does %s have?" % (charOne)) 

    build= input("what build is %s?" % (charOne)) 

    eyes= input("what colour eyes does %s have?" % (charOne)) 

    weaponOfChoice= input("what weapon is %s using?" % (charOne)) 

    defence= input("what defence does %s use?" % (charOne)) 

    s=('hello %s. Am i right to say you have %s right?. You should also be %s and have %s eyes.' % (charOne,hair, build,eyes)) 

    print(s)