CPSC120A
Fundamentals of Computer Science I

Post-lab 18

While Loops

Do one of the following programming problems:

Summation

Create a function called summation_less_than(max_sum). This function should return the largest number of sequential integers that sum to less than the specified positive integer max_sum. Put another way, return the largest \(n\) such that:

$$(\sum_{i=0}^n i) < max\_sum$$


Is Prime

Create a function called is_prime(number) that returns True if the parameter number is a prime number and False otherwise. Assume that number is an integer greater than 1. Recall that number is prime if it is not divisble by any numbers other than 1 and itself.

The function should not use a for loop. Instead, it should use a while loop that stops as soon as a divisor is found. The function should also only have one return statement that is the last statement in the function and not inside the loop.