我向用户询问他们的物理属性(头发颜色,眼睛颜色等)。
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 :(得分: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)
答案 1 :(得分:0)
首先确保“if”后缩进是正确的。 然后,最后一行似乎是错误的。
此示例将起作用:
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)