2015-05-07 2 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) 
Смежные вопросы