Advertisement
PedroPauloFO

Triângulo de Pascal

Jun 26th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # coding: utf-8
  2. # Programação 1, 2014.1 Pedro Paulo
  3. # Triângulo de Pascal
  4.  
  5. indice = int(raw_input())
  6.  
  7. if indice == 1:
  8.     print 1
  9.     print 1
  10.    
  11. if indice == 2:
  12.     print 1
  13.     print 1, 1
  14.     print 1
  15.     print 2
  16.  
  17. if indice > 2:
  18.     print 1
  19.     linha = [1, 1]
  20.     for vert in range (indice-1):
  21.         novalinha = [1]
  22.         for horiz in range (vert):
  23.             novalinha.append(linha[horiz + 1] + linha[horiz])
  24.         novalinha.append(1)
  25.         linha = novalinha
  26.        
  27.         saida = ""
  28.         for x in range (len(linha)):
  29.             saida = saida + str(linha[x])
  30.             if x < (len(linha) - 1):
  31.                 saida = saida + " "
  32.         print saida
  33.     for i in range (indice):
  34.         print 2**i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement