While Loops

Description

While Loops are loops that will continue until a certain condition is true. Here we will write a loop that finds the smallest factorial of m greater than a number n.

Sage Cell

Code

m = 0
n = 100
while (factorial(m) < n):
    m = m + 1
print m

Options

Storing a loop in a subroutine

In order to more easily manage conditions of the loop, we can contain it in a subroutine

Code

def factorialGreaterThanN(n):
    m = 0
    while (factorial(m) < n):
        m = m + 1
    return m

factorialGreaterThanN(100)

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 21 Mar 2019 15:34

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License