Skip to content

Instantly share code, notes, and snippets.

@voyeg3r
Created March 11, 2010 16:54
Show Gist options
  • Select an option

  • Save voyeg3r/329342 to your computer and use it in GitHub Desktop.

Select an option

Save voyeg3r/329342 to your computer and use it in GitHub Desktop.
python - calculando o fatorial
#!/usr/bin/env python
# # -*- coding: UTF-8 -*-
# Criado em:Qui 11/Mar/2010 hs 13:34
# Last Change: Qui 11/Mar/2010 hs 13:34
# vim:ft=python:nolist:nu:
# Instituicao: <+nome+>
# Proposito do script: <+descreva+>
# Autor: <+seuNome+>
# site: <+seuSite+>
import os
# limpando a tela
if os.name == 'posix':
os.system('clear')
else:
os.system('cls')
def fatorial(n):
"""Função recursiva que retorna o valor do fatorial de um numero dado.
"""
if n <= 1:
return 1
else:
return (n * fatorial(n-1))
if __name__ == '__main__':
n = int(raw_input("digite o fatorial a ser calculado: "))
print fatorial(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment