i have a working code but to amend it with some adjustments and add new modules in it i am giving you my script you have to read and understand it then we can make it better :import csv

# Define a dictionary to store the letter mappings
abjad_dict = {
    'ا': (1, 'Fire'), 'أ': (1, 'Fire'), 'إ': (1, 'Fire'), 'آ': (1, 'Fire'),
    'ٱ': (1, 'Fire'), 'ء': (1, 'Fire'), 'ئ': (1, 'Fire'), 'ب': (2, 'Earth'),
    'پ': (2, 'Earth'), 'ج': (3, 'Air'), 'چ': (3, 'Air'), 'د': (4, 'Water'),
    'ڈ': (4, 'Water'), 'ه': (5, 'Fire'), 'ہ': (5, 'Fire'), 'ه‍': (5, 'Fire'),
    'ھ': (5, 'Fire'), 'ة': (5, 'Fire'), 'و': (6, 'Earth'), 'ؤ': (6, 'Earth'),
    'ز': (7, 'Air'), 'ژ': (7, 'Air'), 'ح': (8, 'Water'), 'ط': (9, 'Fire'),
    'ى': (10, 'Earth'), 'ي': (10, 'Earth'), 'ی': (10, 'Earth'), 'ے': (10, 'Earth'),
    'ک': (20, 'Air'), 'ك': (20, 'Air'), 'گ': (20, 'Air'), 'ل': (30, 'Water'),
    'م': (40, 'Fire'), 'ن': (50, 'Earth'), 'ں': (50, 'Earth'), 'س': (60, 'Air'),
    'ع': (70, 'Water'), 'ف': (80, 'Fire'), 'ص': (90, 'Earth'),
    'ق': (100, 'Air'), 'ر': (200, 'Water'), 'ڑ': (200, 'Water'),
    'ش': (300, 'Fire'), 'ت': (400, 'Earth'), 'ٹ': (400, 'Earth'),
    'ث': (500, 'Air'), 'خ': (600, 'Water'), 'ذ': (700, 'Fire'),
    'ض': (800, 'Earth'), 'ظ': (900, 'Air'), 'غ': (1000, 'Water')
}

def calculate_abjad(text):
    total_value = 0
    category_totals = {'Fire': 0, 'Earth': 0, 'Air': 0, 'Water': 0}
    category_letter_counts = {'Fire': 0, 'Earth': 0, 'Air': 0, 'Water': 0}
    letter_count = {}

    for char in text:
        if char != ' ' and char in abjad_dict:
            value, category = abjad_dict[char]
            total_value += value
            category_totals[category] += value
            category_letter_counts[category] += 1
            letter_count[char] = letter_count.get(char, 0) + 1
        elif char != ' ':
            print(f"Warning: Character '{char}' is not in the abjad dictionary and will be ignored.")

    return total_value, category_totals, letter_count, category_letter_counts

def abjad_details(text):
    total_value, category_totals, letter_count, category_letter_counts = calculate_abjad(text)
    
    total_letters = sum(letter_count.values())
    
    print(f"\nDetailed Breakdown:")
    for letter, count in sorted(letter_count.items()):
        value, category = abjad_dict[letter]
        print(f"  {letter}: Count = {count}, Value = {value}, Category = {category}")
    
    print(f"\nTotal Abjad Value: {total_value}")
    print(f"Total Letters: {total_letters}")
    
    print("\nCategory Letter Counts:")
    for category, count in category_letter_counts.items():
        print(f"  {category}: {count} letters")
    
    print("\nCategory Totals:")
    for category, total in category_totals.items():
        print(f"  {category} Total: {total}")

    return total_value, category_totals, letter_count, category_letter_counts

def export_results_to_csv(text, filename='abjad_results.csv'):
    total_value, category_totals, letter_count, category_letter_counts = calculate_abjad(text)
    
    with open(filename, mode='w', newline='', encoding='utf-8') as file:
        writer = csv.writer(file)
        writer.writerow(["Letter", "Count", "Value", "Category"])
        for letter, count in sorted(letter_count.items()):
            value, category = abjad_dict[letter]
            writer.writerow([letter, count, value, category])

        writer.writerow([])
        writer.writerow(["Total Abjad Value", total_value])
        writer.writerow(["Total Letters", sum(letter_count.values())])
        writer.writerow([])
        writer.writerow(["Category", "Total", "Letter Count"])
        for category in category_totals.keys():
            writer.writerow([category, category_totals[category], category_letter_counts[category]])

    print(f"\nResults exported to '{filename}'")

def display_letter_contributions(text):
    index = 0
    letter_contribution_totals = {'Fire': 0, 'Earth': 0, 'Air': 0, 'Water': 0}
    total_contribution_value = 0

    print("\nLetter Contributions:")
    for char in text:
        if char != ' ' and char in abjad_dict:
            index += 1
            value, category = abjad_dict[char]
            contribution = value * index
            total_contribution_value += contribution
            letter_contribution_totals[category] += contribution
            print(f"  {char} = {value} x {index}")
        elif char != ' ':
            print(f"Warning: Character '{char}' is not in the abjad dictionary and will be ignored.")

    print(f"\nTotal Contribution Value: {total_contribution_value}")
    print("\nElemental Contribution Totals:")
    for category, total in letter_contribution_totals.items():
        print(f"  {category}: {total}")

# Main script to get user input and display results
if __name__ == "__main__":
    text = input("Enter the Arabic phrase: ")
    abjad_details(text)
    
    # Display letter contributions and calculate totals
    display_letter_contributions(text)

    # Export results to CSV
    export_results_to_csv(text)