0

我的个人刽子手项目有问题,所以我试图创建一个函数来显示当前未处理的辅音和未处理的元音(第一个和第二个参数),第三个参数是字母集玩家正在猜测。

例如:

>>> guessing_function('dfghjkls','ae','g')
'dfhjkls','ae'

输出是从常量列表或元音列表中猜出的字母。抱歉英语不好,谢谢你们,下面是我写的试图解决但它不起作用的代码,它只是返回您输入的相同内容,它实际上并没有从列表中删除字母。

def make_guessed(unguessed_cons,unguessed_vow,letter):

    new_cons=""
    for i in range(0,len(unguessed_cons)):
        if unguessed_cons[i] == letter:
            new_cons = unguessed_cons.replace (unguessed_cons,new_cons,[i])
    return new_cons 
4

3 回答 3

1

我不太明白你的意思,我猜接下来是你描述的guessing_function的实现,make_guessed和guessing_function一样吗?

def guessing_function(unguessed_cons,unguessed_vow,letter):
    return unguessed_cons.replace(letter,''),unguessed_vow
于 2012-10-19T09:24:48.927 回答
0

提示:您可以通过以下方式make_guessed返回(new_unguessed_cons,new_unguessed_vow)然后更新未猜测的变量:

unguessed_cons, unguessed_vow = make_guessed(unguessed_cons, unguessed_vow, letter)

目前你的函数只返回new_unguessed_cons

于 2012-10-19T09:25:15.690 回答
0
def make_guessed(unguessed_cons, unguessed_vows, letter):

    for con in unguessed_cons:
        if con == letter:
            unguessed_cons = unguessed_cons.replace(letter, '')
            break

    for vow in unguessed_vows:
        if vow == letter:
            unguessed_vows = unguessed_vows.replace(letter, '')
            break

    return unguessed_cons, unguessed_vows
于 2012-10-19T09:28:54.363 回答