How to ask for input again after output is given and transform dictionary into desire output

Hello community

I need to count occurrences in a sentence and after getting the output I would like to have input without having to run the program again. I wrote the following function

import string

def word_count(s):
    counts = dict()
    words = s.split()

    for word in words:
        if word in counts:
            counts[word] += 1
        else:
            counts[word] = 1

    return counts

a_string = input("Enter a word: ").lower() #input from user
new_string = a_string.translate(str.maketrans('', '', string.punctuation))
print(word_count(new_string))# Print occurences of word

In a separate loop I coded the following. Is there a way to unify this while loop with my above function?

while True:
         word = input("Enter word: ")
         if word.isalpha() == True:
            continue
         else:
            print("You did not enter a word")

lastly. if I input the string The quick brown fox jumps over the lazy dog.
I get output

Enter a word: The quick brown fox jumps over the lazy dog.
{'The': 1, 'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'the': 1, 'lazy': 1, 'dog.': 1}

however, I would like my output to look like

Statistics for the word “the”: count: 2 
Statistics for the word“quick”: count: 1 
Statistics for the word“brown”: count:1 
Statistics for the word“fox”: count:1 
Statistics for the word“jumps”: count: 1 
Statistics for the word“over”: count: 1 
Statistics for the word“lazy”: count: 1 
Statistics for the word“dog”: count:1

also, the function should be able to just work with one word. If I input just fox it should look like
Enter a word: fox
Statistics for the word “fox”:
count: 1

Thank you!

I got it…if anyone needs something like this the code is below.

import string

def word_count(s):
    counts = dict()
    words = s.split()

    for word in words:
        if word in counts:
            counts[word] += 1
        else:
            counts[word] = 1

    return counts

while True:
    a_string = input("Enter a word: ").lower() #input from user
    new_string = a_string.translate(str.maketrans('', '', string.punctuation))
    count_statistics = word_count(new_string)
    if a_string == '':
        break

    for word in count_statistics:
        print(f"Staticstics for the word \"{word}\": count {count_statistics[word]}")
1 Like