Last active
March 16, 2016 18:24
-
-
Save Maslor/29d208e9727f855710e1 to your computer and use it in GitHub Desktop.
Breaks down a string an iterates its characters.
This file contains 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 detectSpecificChars(): | |
key = "masterkey" | |
string = raw_input ("Insirt a string: ") | |
if string == key: | |
return None | |
letterArray = [] | |
positionArray = [] | |
for letter in string: | |
letterArray = letterArray + [letter] | |
for i in range(len(letterArray) - 1): | |
if letterArray[i] == "a": | |
positionArray = positionArray + [i] | |
''' | |
A mesma coisa que o loop anterior, mas itera os valores em vez dos indices. | |
for element in letterArray: | |
if element == "a": | |
return "Contem uma letra 'A'" ''' | |
return "Letra 'A' na posicao: \n" + str(positionArray) | |
while True: | |
displayString = detectSpecificChars() | |
if displayString != "" and displayString != None: | |
print(displayString) | |
else: | |
break; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment