IC Python API:Progress Bar

Contents

This article will go over the creation of a progress bar as one of the fundamental building blocks of a functional user interface. This is useful for operations that require a good amount of time to complete. You should include a progress bar in your user interface for scripts that take longer than a couple of seconds to complete. For this example, we'll be creating a prime number finder that looks like the following:

Required Modules

Prime Number Checker

For our CPU intensive operation, we'll be checking for prime numbers from 1 to 10,000. A prime number is natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. The opposite of this is a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 × 3) that are both smaller than 6.

defcheck_prime_number(num):ifnum>1:# Prime numbers are greater than 1foriinrange(2,num):# Check for factorsif(num%i)==0:returnFalseelse:returnTrueelse:# If input number is less than or equal to 1, it is not primereturnFalse