The input and output is as wanted, but why error?

J

John Gordon

In said:
I am trying to solve this problem:

The input and output is as wanted, but my answer keep rejected, here is
my source code http://txt.do/1smv
Please, I need help.

You'll have to explain more about your problem. What, exactly, is wrong?

If, as you say, the input and output is correct, then why do you say there
is a problem?
 
N

Neil Cerutti


Please post your code in and the problem in your message. Here it
is for those reading along:
A. Way Too Long Words
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".

This is a ridiculous abbreviation scheme, but for purposes of
your project that doesn't matter.
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 changes.

Input
The first line contains an integer n (1?=?n?=?100). Each of the
following n lines contains one word. All the words consist of
lowercase Latin letters and possess the lengths of from 1 to
100 characters.

Output
Print n lines. The i-th line should contain the result of
replacing of the i-th word from the input data

Here's your solution so far:
x = input()

if x.isdigit() == False:
i = len(x)
j = i - 1
k = i - 2

xList = list(x)

if len(xList) > 4:
print(xList[0], int(k), xList[j], sep='', end='')
else:
print(x)
else:
SystemExit

The input and output is as wanted, but my answer keep rejected,
here is my source code http://txt.do/1smv

No, your program outputs nothing. That's bound to fail. ;)

How is your program supposed to work, in your own words?
 
G

geezle86

x = input()
if x.isdigit() == False:
i = len(x)
j = i - 1
k = i - 2

xList = list(x)

if len(xList) > 4:
print(xList[0], int(k), xList[j], sep='', end='')
else:
print(x)
else:
SystemExit

I just dont understand what is wrong, seriously. I mean. They said:

"..if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation."

and:
"... 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."

I solved it with my:

xList = list(x)

if len(xList) > 4:
print(xList[0], int(k), xList[j], sep='', end='')
else:
print(x)

really, i dont know why.. :(
 
G

geezle86

x = input()
if x.isdigit() == False:
i = len(x)
j = i - 1
k = i - 2

xList = list(x)

if len(xList) > 4:
print(xList[0], int(k), xList[j], sep='', end='')
else:
print(x)
else:
SystemExit

I just dont understand what is wrong, seriously. I mean. They said:

"..if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation."

and:
"... 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."

I solved it with my:

xList = list(x)

if len(xList) > 10: #I changed it from 4, still not accepted
print(xList[0], int(k), xList[j], sep='', end='')
else:
print(x)

really, i dont know why.. :(
 
G

geezle86

Well,
i've changed the "if len(xList).." from 4 to 10

But still, it is not accepted :(
 
M

Mark Lawrence

Well,
i've changed the "if len(xList).." from 4 to 10

But still, it is not accepted :(

Where is your code that meets these requirements?

Input
The first line contains an integer n (1?=?n?=?100). Each of the
following n lines contains one word. All the words consist of
lowercase Latin letters and possess the lengths of from 1 to
100 characters.

Output
Print n lines. The i-th line should contain the result of
replacing of the i-th word from the input data
 
N

Neil Cerutti

Your first problem is that input() returns text only up the a
newline, and then stops.

So you are reading the initial number line, but never reading the
rest of the lines.
 
R

rusi

I am trying to solve this problem:

http://codeforces.com/problemset/problem/71/A

The input and output is as wanted, but my answer keep rejected, here is my source code http://txt.do/1smv

Please, I need help.

I suggest you take your problem one step at a time, like this:

1. You need to convert a string like "localization" to "l10n"
Write a function that takes strings like "localization" and RETURNS strings
like "l10n". The function SHOULD NOT use print.

2. Now you need to convert a list of strings like
["word", "localization", "internationalization",
"pneumonoultramicroscopicsilicovolcanoconiosis" ]
to a list like
["word", "l10n", "i18n", "p43s"]
You can use the above function (1). NO PRINTS

3. Use the function in 2 above to solve the problem.
Here you may use print
 
D

Dave Angel

really, i dont know why.. :(

How about because you do a system exit on the first line of their
input? The one that's all digits. And even if you get past that, you
only process one of their words.
 
D

Dennis Lee Bieber

x = input()

if x.isdigit() == False:
i = len(x)
j = i - 1
k = i - 2

xList = list(x)

if len(xList) > 4:
print(xList[0], int(k), xList[j], sep='', end='')

First off -- there is no need to turn the "word" into a list of
characters... You can index strings. x[0] is the first character, x[-1] is
the last.

Second... k is already an integer, so there is no need to convert it
into an integer.

Third... i, j, k aren't really needed -- for something this simple

if not x.isdigit() and len(x) > 4:
print ("%s%s%s" % (x[0], len(x)-2, x[-1])
else:
print (x)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top