renix1

Fatorando um número em Python

May 5th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. #-*- coding:utf-8 -*-
  2. # PROGRAMA APENAS PARA REVISÃO
  3.  
  4. #ETAPA UM
  5. def num_absoluto(xNum):
  6.     xNum*=-1
  7.     return(xNum)
  8. def fatorial (fatorial):
  9.     resultado = 1
  10.     while fatorial > 1:
  11.         resultado*=fatorial
  12.         fatorial-=1
  13.     return(resultado)
  14. #ETAPA DOIS
  15. try:
  16.     numero = int(input("Digite um número: "))
  17.     if (numero < 0):
  18.         numero = num_absoluto(numero)
  19.         print("O fatorial é: ", fatorial(numero))
  20.     else:
  21.         print("O fatorial é: ", fatorial(numero))
  22. except:
  23.     print("Erro inesperado! Fechando...")
  24.     exit()
Advertisement
Add Comment
Please, Sign In to add comment