python

时间:2018-03-09 15:21:12

标签: python string list debugging comparison

def show_hidden_word(secret_word, old_letters_guessed):
i = 0
new_string = ""
while i < len(secret_word):
    j = 0
    print(1)
    for j in old_letters_guessed:
        if secret_word[i] == old_letters_guessed[j]:
            new_string += secret_word[i]
        print(old_letters_guessed[j])
        j += 1
    print(secret_word[i])
    i += 1
return new_string

为什么这些字符串之间的比较不起作用?有人可以帮忙解决它吗?

2 个答案:

答案 0 :(得分:0)

这应该有所帮助。您可以将输入转换为int或9转换为字符串'9'

choice = input('Enter an option - out of the loop')
while int(choice) != 9:  #or while choice != '9'
    menu(list_of_products, choice)
    choice = input('Enter an option - in the loop')

答案 1 :(得分:-1)

也许choice是一个字符串,你需要将它转换为int。