1

我有的

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]

4

3 回答 3

3

这是有关 Python string.format 方法的一些信息。

x=raw_input("guess? ")
print "Incorrect guess [{}].".format(x)
于 2013-07-31T03:41:48.793 回答
0
print "Incorrect Guess [%s]" % guess

或者

print "Incorrect Guess [" + guess + "]"
于 2013-07-31T03:43:06.687 回答
0

raw_input()函数返回一个字符串,因此您只需在 print 语句中添加“guess”:

print "Incorrect Guess [", guess, "]"
于 2013-07-31T03:45:10.867 回答