challenge.py 754 B

12345678910111213141516171819202122
  1. def find_duplicate(string):
  2. values = list(string)
  3. for i, value in enumerate(values):
  4. values[i] = values[i].lower()
  5. duplicates = []
  6. for i, letter in enumerate(values):
  7. if letter == " ":
  8. pass
  9. elif i == len(values)-1:
  10. pass
  11. elif values[i] == values[i+1]:
  12. duplicates.append(letter)
  13. if len(duplicates) == 0:
  14. return "No duplicates found."
  15. elif len(duplicates) == 1:
  16. return f"{duplicates[0]} is the duplicate character."
  17. else:
  18. return f"{', '.join(duplicates)[:-1]} and {duplicates[-1]} are duplicate characters.".replace(" ", " ")
  19. input_string = input("Which string do you want to find duplicates of? ")
  20. print(find_duplicate(input_string))