python - 将 [ ] 替换为 raw_input

标签 python replace

我有什么

import random

listofLetters =['k', 'i', 'n', 'g']
x = random.choice(listofLetters)
print x 

listDash = []

print "Welcome to Gues the Letter Game!"
print " "
print "=" * 5 + "Start of Game" + "=" * 5 
print ['_', '_', '_', '_', '_']
print " "

maxLife = 4

print "*" * 3 + "Life Line" + "*" * 3
print "-+" * maxLife
print "$|" * maxLife
print "-+" * maxLife
print " " 


guess = raw_input("Enter your guess: ")
howmanyletter = len(guess)

if guess == x:

    print "*" * 3 + "Life Line" + "*" * 3
    print "-+" * maxLife
    print "$|" * maxLife
    print "-+" * maxLife

else:
    print "Incorrect Guess []

我希望将 [] 替换为猜测

例如[k]

最佳答案

以下是有关 Python 的一些信息 string.format method .

x=raw_input("guess? ")
print "Incorrect guess [{}].".format(x)

关于python - 将 [ ] 替换为 raw_input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961147/

相关文章:

python - django-mptt order_by() 在递归树期间不工作

python - 样本数量不一致是什么意思?

javascript - Jquery 替换每个

php - 如何替换多维数组中的键并保持顺序

python - 用漂亮的汤在 python 中提取深度嵌套的 href

python - 为什么 SciPy 的 loadmat 在读取 200 MB 的 Matlab 结构时抛出 MemoryError

python - 如何实现对象属性的两个方向

string - .bat 文件搜索和替换结构化文本文件中的字符串

SQL Server 替换、删除特定字符后的所有内容

C++ - 在文本文件中查找和替换(标准系统库)