在输入提示中使用字符串格式?

时间:2015-10-07 13:28:52

标签: python string

我确信我很容易看到我在这里要做的事情。我完全错了还是犯了一个简单的错误?我想要它说:

  

'PlayerA的名字',请选择..

playerA = raw_input("Please enter your name: ")
playerB = raw_input("Please enter your name: ")
choiceA = input("%s, Please choose; Rock (R), Paper (P), or Scissors (S): ") % (playerA)
choiceB = input("%s, Please choose; Rock, Paper, or Scissors: ") % (playerB)

2 个答案:

答案 0 :(得分:2)

您的替换需要完全在括号内完成:

raw_input("%s, Please choose; Rock (R), Paper (P), or Scissors (S): " % (playerA))

否则将在通话的结果上完成。

此外,您似乎没有理由有时使用raw_input并输入其他时间。如果您使用的是Python 2,请使用raw_input 始终

答案 1 :(得分:0)

问题在于你的问题。试试这样:

playerA = raw_input("Please enter your name: ")
playerB = raw_input("Please enter your name: ")
choiceA = input("%s, Please choose; Rock (R), Paper (P), or Scissors (S): " % (playerA))
choiceB = input("%s, Please choose; Rock, Paper, or Scissors: " % (playerB))