Advertisement
AllanRocha

Python to Zumbi V

Jul 17th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. with open("texto.txt") as aqv:        #Abre o arquivo e separada por espaço
  2.     numbers = aqv.read().split(" ")
  3.     aqv.close()
  4.  
  5. total_numbers_ok = 0
  6.  
  7. for number in numbers: #Percorre a lista gerada
  8.     number = number.strip()  #Segura contra caracteres especiais como \n
  9.     check = 0  #Caso algum número quebre a condição 1 no for abaixo
  10.     first = int(number[0])
  11.     last = int(number[len(number) - 1])
  12.     soma = last # É igual pois no for abaixo ele não soma o último algarismo number[len(c) - 1]
  13.  
  14.     if first == last:
  15.         continue #Anula o resto do for já que quebra uma condição
  16.  
  17.     for c in range(len(number)-1): #For até o penultimo algarismo, para evitar error de list index
  18.         soma += int(number[c])
  19.         if number[c] == number[c+1]:
  20.             check = 1 #Altera o check para especificar que quebrou a condição
  21.             break
  22.  
  23.     if soma % 2 == 0 and check == 0: # Testa a 2 condição e o check
  24.         total_numbers_ok += 1 #Se tudo ocorrer bem, ele resulta em 39
  25.  
  26.  
  27. print("Números que estão de acordo:%d" % total_numbers_ok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement