Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 106 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,126 @@
# 🏛️ Roman to Integer Converter (Python)
# Roman to Integer Converter in Python 🏛️

Convert **Roman numerals** to **integers** in Python using a clean and beginner-friendly approach.
This simple script demonstrates how to implement Roman numeral conversion logic using Python data structures and control flow.
![GitHub release](https://img.shields.io/github/release/Gabi111243/roman-to-integer-python.svg) ![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg) ![Open Source](https://img.shields.io/badge/Open%20Source-Yes-brightgreen.svg)

---
Welcome to the **Roman to Integer Converter** repository! This project provides a simple and efficient way to convert Roman numerals into integers using Python. Whether you are a beginner looking to enhance your coding skills or an experienced developer interested in algorithms, this project is designed for you.

## 📌 Overview
## Table of Contents

Roman numerals are composed of the following seven symbols:
- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [Algorithm](#algorithm)
- [Contributing](#contributing)
- [License](#license)
- [Releases](#releases)

| Symbol | Value |
|--------|-------|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
## Introduction

### Special Cases:
Roman numerals have been used for centuries and are still relevant today. This project aims to bridge the gap between ancient numeral systems and modern programming. By converting Roman numerals to integers, you can easily perform calculations and data manipulations.

- I before V or X (e.g. IV = 4, IX = 9)
- X before L or C (e.g. XL = 40, XC = 90)
- C before D or M (e.g. CD = 400, CM = 900)
## Installation

---
To get started with this project, you need to have Python 3.8 or higher installed on your machine. You can download Python from the official website: [Python Downloads](https://www.python.org/downloads/).

## ✅ Features
Once you have Python installed, you can clone this repository using the following command:

- Converts valid Roman numerals (1 - 3999) into integers
- Handles all subtractive cases
- Clean O(n) algorithm
- Beginner-friendly code
- Can be integrated into larger Python projects
```bash
git clone https://github.com/Gabi111243/roman-to-integer-python.git
```

---
Navigate to the project directory:

## 🚀 Usage
```bash
cd roman-to-integer-python
```
# Example usage
if __name__ == "__main__":
converter = Solution()
print(converter.romanToInt("XI")) # Output: 11

You can also install the required packages using pip:

```bash
pip install -r requirements.txt
```
## 📂 Project Structure

## Usage

To convert a Roman numeral to an integer, simply run the script from the command line. You can provide the Roman numeral as an argument:

```bash
python roman_to_integer.py X
```
roman-to-integer-python/
├── roman_converter.py # Main script
├── test_cases.py # (Optional) Unit tests
├── README.md # Project documentation
└── LICENSE # MIT or any license

This will output:

```
10
```
## 📄 License
This project is licensed under the **MIT License**.
Feel free to use, modify, and distribute it for personal or commercial use.

## 👨‍💻 Author
Muawiya Amir
+ 🔗 GitHub: [Muawiya-contact](https://github.com/Muawiya-contact)
+ 📺 YouTube: [@Coding_Moves](https://www.youtube.com/@Coding_Moves)
You can also test various Roman numerals by running the script multiple times with different inputs.

## Features

- **Beginner-Friendly**: The code is simple and easy to understand, making it suitable for beginners.
- **Educational**: Learn about Roman numerals and their conversion process.
- **Command-Line Tool**: Easily convert Roman numerals from the command line.
- **Open Source**: Contribute to the project and improve it further.
- **Data Structures**: Understand how to use dictionaries and lists effectively.

## Algorithm

The algorithm used in this project is straightforward. Here’s a brief overview:

1. **Mapping**: Create a mapping of Roman numerals to their integer values.
2. **Iteration**: Iterate through the Roman numeral string from left to right.
3. **Comparison**: If the current numeral is less than the next numeral, subtract its value. Otherwise, add its value.
4. **Return Result**: After processing the entire string, return the total value.

Here is a simple code snippet that illustrates the algorithm:

```python
def roman_to_integer(s: str) -> int:
roman_map = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
}

total = 0
prev_value = 0

for char in reversed(s):
value = roman_map[char]
if value < prev_value:
total -= value
else:
total += value
prev_value = value

return total
```

## Contributing

We welcome contributions! If you have ideas for improvements or new features, feel free to submit a pull request. Please ensure your code follows the existing style and includes tests.

1. Fork the repository.
2. Create a new branch for your feature.
3. Make your changes and commit them.
4. Push to your branch and create a pull request.

## License

This project is licensed under the MIT License. Feel free to use, modify, and distribute it as you wish.

## Releases

You can find the latest releases of this project [here](https://github.com/Gabi111243/roman-to-integer-python/releases). Please download the necessary files and execute them as per the instructions provided.

For further updates and information, check the "Releases" section in the repository.

---

Thank you for checking out the **Roman to Integer Converter**! We hope this project helps you understand both Roman numerals and Python programming better. Happy coding!
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Required packages