Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python factorial code
#1
Hi all,
I am new to scientific python. While trying to follow the code below i always get "Factorial does not exist" response. I am using python 3.8 but the code is written in python 2.7 and it works. I have broken the code and ran it piecewise, still the code will not work properly when i enter i.e. 6 for n etc...integers greater than 1. I am out of tricks so please help me understand this factorial code: Thank you very much in advance!

f = 1
n = input("Enter a value for n:")
if isinstance(n, int): #check whether the value is integer
    if n == 1 or 0:
        print ("Execution at if ")
        print ("The value of {}! = {}" .format(n, f))
        exit
    elif n < 0:
        print ("Execution at elif ")
        print ("n is negative")
    else:
        print ("Executoin at else")
        for i in range(2, n+1):
            f *= i
        print ("The value of {}! = {}" .format(n, f))
else:
    print ("Factorial does not exist")
Reply


Messages In This Thread
Python factorial code - by timebrahimy - Sep-26-2020, 09:42 PM
RE: Python factorial code - by Larz60+ - Sep-26-2020, 09:49 PM
RE: Python factorial code - by timebrahimy - Sep-26-2020, 09:53 PM
RE: Python factorial code - by deanhystad - Sep-26-2020, 10:14 PM
RE: Python factorial code - by timebrahimy - Sep-27-2020, 12:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing recursion and loops using two scripts (basic factorial) Drone4four 3 2,297 Oct-11-2020, 06:48 PM
Last Post: deanhystad
  factorial, repeating Aldiyar 4 2,860 Sep-01-2020, 05:22 PM
Last Post: DPaul
  factorial using recursive function spalisetty06 12 4,183 Aug-25-2020, 03:16 PM
Last Post: spalisetty06
  minor mistake in code for factorial spalisetty06 2 1,928 Aug-22-2020, 05:00 PM
Last Post: spalisetty06
  Factorial Code is not working when the given number is very long integer Raj_Kumar 2 2,359 Mar-31-2020, 06:40 PM
Last Post: deanhystad
  Want to print each iteration of factorial program sbabu 10 4,657 Jan-09-2020, 07:25 AM
Last Post: perfringo
  Factorial sketch(python 3) KingArthur526 1 2,004 Sep-25-2019, 01:51 PM
Last Post: ichabod801
  Factorial leodavinci1990 8 4,522 Jul-19-2019, 10:59 PM
Last Post: leodavinci1990

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020