Skip to content

πŸ” Python program that performs prime factorization of a given number and returns all prime factors in order.

Notifications You must be signed in to change notification settings

moroniq/prime_factorization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

# Prime Factorization πŸ”’

This simple Python script takes a number from the user and returns its prime factors.

## πŸ“Œ Project Description

The goal of this project is to take a single integer input and break it down into its prime components β€” if any.

For example, 60 becomes \[2, 2, 3, 5].

The script uses a basic loop and modulo division to determine whether a number is divisible by an incrementing divisor, starting from 2. Every time it finds a divisor, it divides the original number by it and stores it in a list.

## πŸ’‘ What You'll Learn

- Basic number theory (prime factorization)

- Using while loops and conditionals

- The try/except/finally block for input validation

- Working with integer division (//) in Python

- Building and printing a list of results

## πŸš€ Example

Give a number: 39999

Prime factors are: [3, 67, 199]

## 🧠 How It Works

1. The program starts with the smallest prime (2).

2. It checks if the number is divisible by the current divisor.

3. If yes, it adds the divisor to a list and divides the number.

4. If not, it moves to the next integer.

5. The loop continues until the number is reduced to 1.

## πŸ“‚ Files Included

- prime\_factorization.ipynb β€” Jupyter Notebook with the working code

- README.md β€” this file

🧩 Interactive Version: Choose Step by Step

In addition to the standard prime factorization, this project includes an interactive mode.

After each found prime factor, the program asks the user whether to continue or stop.

This allows the user to step through the factorization process one factor at a time.

Example:

Give a number: 60 Do you want to continue? yes Actual prime list is: [2] Do you want to continue? yes Actual prime list is: [2, 2] Do you want to continue? no Prime factors are: [2, 2]


Created with πŸ’» by Olga KΔ™ska

About

πŸ” Python program that performs prime factorization of a given number and returns all prime factors in order.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published