Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("texto.txt") as aqv: #Abre o arquivo e separada por espaço
- numbers = aqv.read().split(" ")
- aqv.close()
- total_numbers_ok = 0
- for number in numbers: #Percorre a lista gerada
- number = number.strip() #Segura contra caracteres especiais como \n
- check = 0 #Caso algum número quebre a condição 1 no for abaixo
- first = int(number[0])
- last = int(number[len(number) - 1])
- soma = last # É igual pois no for abaixo ele não soma o último algarismo number[len(c) - 1]
- if first == last:
- continue #Anula o resto do for já que quebra uma condição
- for c in range(len(number)-1): #For até o penultimo algarismo, para evitar error de list index
- soma += int(number[c])
- if number[c] == number[c+1]:
- check = 1 #Altera o check para especificar que quebrou a condição
- break
- if soma % 2 == 0 and check == 0: # Testa a 2 condição e o check
- total_numbers_ok += 1 #Se tudo ocorrer bem, ele resulta em 39
- print("Números que estão de acordo:%d" % total_numbers_ok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement