check for repeated characters/letter in a string

前端 未结 3 2018
感情败类
感情败类 2021-01-29 07:12

hi i want to check if a string from user input has two repeated characters/letters in a string next to eachother.. i have a simple code to check if the first letter and second l

3条回答
  •  Happy的楠姐
    2021-01-29 07:23

    As the comments already mentioned you should use a for loop:

    def two_same(string)
       for i in range(len(string)-1):
          if string[i] == string[i+1]:
             return True
       return False
    
    result = ""
    while not two_same(result):
       result = input("enter the same letter twice:")
    print(result)
    

提交回复
热议问题