如何将列表中的字符串放在变量中? [蟒蛇]

时间:2017-02-20 20:36:50

标签: python list

word =("Enter a word: ")
listword = list(word)

def final():
    while True:
        index = int(input("Enter an index: "))
        if index > len(word) - 1:
           input print "Try again"
            continue
        else:
            break
    while True:
            letter = input("Enter a letter: ")
            if len(letter) == 1:
                break
            else:
                continue
    listword[index] = letter
    print listword
while True:
    final()

1 个答案:

答案 0 :(得分:0)

我想这可能就是你的意思了:

word = input("Enter a word: ")
listword = list(word)

while True:
    index = int(input("Enter an index: "))
    if index <= len(word) - 1:
        break
    print("Try again")

while True:
    letter = input("Enter a letter: ")
    if len(letter) == 1:
        break

listword[index] = letter
print("".join(listword))