Python代码连续字母

2024-09-29 22:30:36 发布

您现在位置:Python中文网/ 问答频道 /正文

def consecutiveLetter(str): 
    x=0 
    flag=0 
    while(x<(len(str)-2)): 
        i=ord(str[x]) 
        j=ord(str[x+1]) 
        k=ord(str[x+2]) 
        if((i+1)==j and (j+1)==k): 
            print("String has 3 consecutive letters") 
            flag=1 
            break 
        else: 
            x=x+1 
if(flag==0):
    print("String has no 3 consecutive letters")

当我在python中运行它时,它要求我输入consercutiveletters('then the word')。在

我只想输入这个单词,它会告诉我它是否有3个连续的字母。请帮忙!在


Tags: andstringlenifdefflaghasprint

热门问题