Advertisement
PedroPauloFO

Números Oscilantes

Jun 18th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # coding: utf-8
  2. # Programação 1, 2014.1 Pedro Paulo
  3. # Números Oscilantes
  4.  
  5. codigo = raw_input()
  6.  
  7. tamanho = len(codigo)
  8.  
  9. if int(codigo[0]) % 2 == 0:
  10.     comeco = "par"
  11. else:
  12.     comeco = "impar"
  13.  
  14. verificador = 0
  15. cont = 0
  16.  
  17. if comeco == "par":
  18.     for numero in codigo:
  19.         cont += 1
  20.         if cont % 2 == 1 and int(numero) % 2 == 0:
  21.             verificador += 1
  22.         if cont % 2 == 0 and int(numero) % 2 == 1:
  23.             verificador += 1
  24.            
  25. if comeco == "impar":
  26.     for numero in codigo:
  27.         cont += 1
  28.         if (cont % 2) == 1 and (int(numero) % 2) == 1:
  29.             verificador += 1
  30.         if (cont % 2) == 0 and (int(numero) % 2) == 0:
  31.             verificador += 1
  32.            
  33. if verificador == tamanho:
  34.     v_ou_f = "verdadeiro"
  35. else:
  36.     v_ou_f = "falso"
  37.    
  38. print "%s: %d algarismos." % (v_ou_f, tamanho)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement