Code Forces "Q-71A Way Too Long Words" Not Submitting. – token expected Python3

Question:

I’ve just started using Code Forces to improve my problem solving skills and note been able pass the Way Too Long Words problem although my outputs are correct(?)
Here is the link to the question:
https://codeforces.com/contest/71/problem/A

Also the question is (For those who don’t want to go to the site):

Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.

Let’s consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.

This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn’t contain any leading zeroes.

Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".

You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any chan

And my code is:

word = input()
while not word.isnumeric():
    if len(word) > 10:
        between = (len(word)-2)
        first, last = (word[0], word[-1])
        print(f"{first}{between}{last}")
        break
    elif len(word) <= 10:
        print(word)
        break

The site wants also gives some examples:

Example input:
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

Example output:
word
l10n
i18n
p43s

As you can see it require me to not output anything when the input is an integer and that’s were I believe I fail.
Any reason why?

Asked By: user13099216

||

Answers:

The number at the top of the list is the number of words. You want to use it as an input so you can create an array of the words you are potencially shortening. Some languages need to initalize an array size prior to creation. Below is a solution that works. It takes the first input as an integer and if it is larger that 100 it stops (as in the instructions they say n shouldn’t be larger than 100) It then cycles through the rest of the inputs adding them to an array before finishing off with shortening the words that need shortening. You’re logic was sound by the way, that code does work, but it would only work for a single input before having to restart.

while True:
    n = int(input())
    if n in range(1,101):
        break
word_list = []
for i in range(n):
    while True:
        word = input()
        if len(word) in range(1,101):
            break
    word_list.append(word.lower())

for _ in word_list:
    if len(_) > 10:
        print(_[0] + str(len(_[1:-1])) + _[-1])
    else:
        print(_)`
Answered By: Cameron Ferguson

JAVA easiest solution to the problem –

public static void printAbbv(String s){
    if (s.length() <= 10) {
        System.out.print(s);
        return;
    }

    System.out.print(s.charAt(0));

    int count = 0;
    for (int i = 1; i < s.length() - 1; i++) {
        count++;
    }
    
    System.out.print(count + "" + s.charAt(s.length() - 1));
}
Answered By: Ashish Ram
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.