Python代码连续字母

时间:2017-04-12 01:33:54

标签: 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中运行它时,它要求我输入consecutiveLetters('然后是单词')。

我只是希望能够输入单词并告诉我它是否有3个连续的字母。请帮忙!

1 个答案:

答案 0 :(得分:0)

WindowsOS

您可以像这样简化my_str = input('word: ') # get user input consecutiveLetter(my_str) # and pass it to your function 函数:

consecutiveLetter