Last active
October 9, 2022 17:23
-
-
Save rsalaza4/5f6982a0fbb881187621af875fac9f92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def max_repeated_character(word): | |
| # Validate that provided word is not an empty string | |
| if word != "": | |
| # Initialize variables | |
| repeated_character = word[0] | |
| character_repeated_times = 1 | |
| max_repeated_times = 1 | |
| # Loop through all characters in word provided | |
| for i in range(len(word)-1): | |
| # Check if the next immediate character is equal to the current character | |
| if word[i] == word[i+1]: | |
| character_repeated_times +=1 | |
| # Update variables if applicable | |
| if character_repeated_times > max_repeated_times: | |
| max_repeated_times = character_repeated_times | |
| repeated_character = word[i] | |
| # Restart counter if the next immediate character is not equal to the current character | |
| else: | |
| character_repeated_times = 1 | |
| return (repeated_character, max_repeated_times) | |
| # In case that the user provided an empty string | |
| else: | |
| return "Error! The provided word must have at least one character." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment