Technique #2 – Factorial ProgramĬode: # Python program to determine the value of factorial for a given Number At the end of the last execution, the value of the factorial is printed. This loop’s range is maintained between 1 and one value greater than the number being keyed in. In the next instance, the factorial for a given value is determined by the formula below being executed in a loop with the iterator value incremented by one. also, if the value keyed is equal to zero, then the factorial value for zero, which is one, is printed. so the check is implied such that the keyed in value is greater than zero. this is because the factorial value for a negative integer cannot be calculated. The first check carried out is to settle on whether the key value is a positive integer. Alongside, the variable ‘Factorial’ is initialized with a value of 1. Print("The factorial value for the ", Number, "is", factorial)Įxplanation: The program calculates the factorial of a number using the looping technique here, the specific integer value for which the factorial value has to be calculated is keyed in into the ‘Number’ variable. # For loop to handle the factorial calculation Print(" ! ! ! ! 1 is the factorial value 0 ! ! ! ! ") # The default factorial value for zero is one and this is printed here Print(" ! ! ! ! ! Factorial value cannot be intended for negative integers ! ! ! ! ! ") # to verify that the given number is greater than zero incase it is less than zero then the Number = int(input(" Enter the number for which factorial value to be determined : ")) # modifying the value keyed in will produce a different result Web development, programming languages, Software testing & others
0 Comments
Leave a Reply. |