About 46,700 results
Open links in new tab
  1. Write factorial with while loop python - Stack Overflow

    Set up your initial value for i before the loop; use the while condition to detect when i reaches its limit; increment i inside the loop. – khelwood Commented Feb 17, 2016 at 20:46

  2. Function for factorial in Python - Stack Overflow

    def factorial(n): return 1 if n == 0 else n * factorial(n-1) One line lambda function approach: (although it is not recommended to assign lambda functions directly to a name, as it is considered a bad practice and may bring inconsistency to your code. It's always good to know. See PEP8.) factorial = lambda n: 1 if n == 0 else n * factorial(n-1)

  3. python - Using a while loop to calculate the factorial of user input ...

    Jul 2, 2021 · I'm trying to make while loop that calculates the factorial of user's input number. But now my program takes the factorial of the first input number and uses that result when calculating the next factorials.

  4. Python factorial that requires "while" loop - Stack Overflow

    May 30, 2017 · I am a python student that's new to python and I am required to write a program that calculates the factorial of an input number to find the possible ways to arrange letters in a Scrabble game with only the "while" loop construct. For example: I request for an input number from a user through a line like this initially:

  5. factorial with for loop in python - Stack Overflow

    Write factorial with while loop python. 0. basic FACTORIAL algorithm on PYTHON with "while" loop. 4.

  6. Factorial in Python using while - Stack Overflow

    Dec 16, 2014 · First of all, none of your code changes the value of n, so the loop will run indefinitely unless n == 1 when the function is called. Secondly, you aren't accumulating a partial product inside the loop (hint: before the loop set result =, then inside it multiply the current value of result by the value of n.

  7. python - Output factorials with while loop - Stack Overflow

    Mar 1, 2017 · My code is supposed to take an input and then output the factorials up to the inputted number For example, if the input is 8 the output would be 1,2,6,24,120,720,5040,40320. I thought I had the ...

  8. python - How to use the while loop to get the factorial of an …

    Jul 21, 2016 · Write factorial with while loop python. 0. basic FACTORIAL algorithm on PYTHON with "while" loop. 1.

  9. Python Factorial while loop - Stack Overflow

    Jul 13, 2017 · You are not resetting the value of factorial in between runs of your while loop. You should move the line . factorial= 1 to be after. #Calculate and display factorial of number while input is valid while number != 0 and number >=1:

  10. python - Calculating a factorial using loops in Python3 - Stack …

    Oct 31, 2019 · Write factorial with while loop python. 0. basic FACTORIAL algorithm on PYTHON with "while" loop. 4.

Refresh