> For the complete documentation index, see [llms.txt](https://pda-assignments.consoleflare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pda-assignments.consoleflare.com/python-for-data-analytics/1.python/3.python-projects/hamming-distance.md).

# Hamming distance

Hamming distance is calculated by counting the number of unmatching characters between two same length strings.

Example:  The hamming distance between RAT and SAT will be 1. As only 1 character from both strings (R and S) is different.<br>

```
def hamming_distance(str1, str2):
    if len(str1) != len(str2):
        print("Error: Input strings must have the same length")
        return None
    else:
        distance = 0
        for char1, char2 in zip(str1, str2):
            if char1 != char2:
                distance += 1

        return distance


string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")

distance = hamming_distance(string1, string2)

if distance is not None:
    print(f"The Hamming distance between '{string1}' and '{string2}' is: {distance}")

```
