While Loops

2 / 5

A while loop can be used to perform calculations by repeating steps. For example, to calculate the sum of numbers from 1 to n, you could use:

total = 0
count = 1
while count <= n:
    total = total + count
    count = count + 1

This loop adds each number to total until count exceeds n.

Factorial

Input an integer n. Compute and print the factorial of n.

Hint: the factorial of n is the product of all positive integers up to n. For example, if n is 5, the factorial is 5 * 4 * 3 * 2 * 1 = 120.

Congratulations!

You passed the !

Welcome!

Would you like a guided tour on how to use Vibewise?

Your email has been verified!