Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60942 > unrolled thread
| Started by | geezle86@gmail.com |
|---|---|
| First post | 2013-12-03 07:48 -0800 |
| Last post | 2013-12-03 23:52 +0000 |
| Articles | 12 — 8 participants |
Back to article view | Back to comp.lang.python
The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 07:48 -0800
Re: The input and output is as wanted, but why error? John Gordon <gordon@panix.com> - 2013-12-03 16:03 +0000
Re: The input and output is as wanted, but why error? Neil Cerutti <neilc@norwich.edu> - 2013-12-03 16:10 +0000
Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:35 -0800
Re: The input and output is as wanted, but why error? Dave Angel <davea@davea.name> - 2013-12-03 12:58 -0500
Re: The input and output is as wanted, but why error? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-03 17:54 -0500
Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:36 -0800
Re: The input and output is as wanted, but why error? Neil Cerutti <neilc@norwich.edu> - 2013-12-03 16:58 +0000
Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:38 -0800
Re: The input and output is as wanted, but why error? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-03 16:51 +0000
Re: The input and output is as wanted, but why error? rusi <rustompmody@gmail.com> - 2013-12-03 09:19 -0800
Re: The input and output is as wanted, but why error? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-03 23:52 +0000
| From | geezle86@gmail.com |
|---|---|
| Date | 2013-12-03 07:48 -0800 |
| Subject | The input and output is as wanted, but why error? |
| Message-ID | <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-12-03 16:03 +0000 |
| Message-ID | <l7kvcj$b2$1@reader1.panix.com> |
| In reply to | #60942 |
In <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> geezle86@gmail.com writes: > 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. 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? -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-12-03 16:10 +0000 |
| Message-ID | <mailman.3518.1386087064.18130.python-list@python.org> |
| In reply to | #60942 |
On 2013-12-03, geezle86@gmail.com <geezle86@gmail.com> wrote: > I am trying to solve this problem: > > http://codeforces.com/problemset/problem/71/A 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? -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | geezle86@gmail.com |
|---|---|
| Date | 2013-12-03 08:35 -0800 |
| Message-ID | <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com> |
| In reply to | #60942 |
> 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.. :(
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-12-03 12:58 -0500 |
| Message-ID | <mailman.3526.1386093444.18130.python-list@python.org> |
| In reply to | #60947 |
On Tue, 3 Dec 2013 08:35:20 -0800 (PST), geezle86@gmail.com wrote: > 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. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-12-03 17:54 -0500 |
| Message-ID | <mailman.3535.1386111296.18130.python-list@python.org> |
| In reply to | #60947 |
On Tue, 3 Dec 2013 08:35:20 -0800 (PST), geezle86@gmail.com declaimed the
following:
>> 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)
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | geezle86@gmail.com |
|---|---|
| Date | 2013-12-03 08:36 -0800 |
| Message-ID | <01b71b3a-f324-4850-a566-b5402e48baf0@googlegroups.com> |
| In reply to | #60942 |
> 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.. :(
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-12-03 16:58 +0000 |
| Message-ID | <mailman.3522.1386089951.18130.python-list@python.org> |
| In reply to | #60948 |
On 2013-12-03, geezle86@gmail.com <geezle86@gmail.com> wrote: >> x = input() 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. -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | geezle86@gmail.com |
|---|---|
| Date | 2013-12-03 08:38 -0800 |
| Message-ID | <66f9ae94-9ba6-4468-a43f-57b19f57816e@googlegroups.com> |
| In reply to | #60942 |
Well, i've changed the "if len(xList).." from 4 to 10 But still, it is not accepted :(
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-03 16:51 +0000 |
| Message-ID | <mailman.3520.1386089470.18130.python-list@python.org> |
| In reply to | #60949 |
On 03/12/2013 16:38, geezle86@gmail.com wrote: > 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 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-12-03 09:19 -0800 |
| Message-ID | <49c77ea4-21ab-40f2-a141-975b6f4daa39@googlegroups.com> |
| In reply to | #60942 |
On Tuesday, December 3, 2013 9:18:43 PM UTC+5:30, geez...@gmail.com wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-12-03 23:52 +0000 |
| Message-ID | <l7lqrp$rmj$2@dont-email.me> |
| In reply to | #60942 |
On Tue, 03 Dec 2013 07:48:43 -0800, geezle86 wrote: > I am trying to solve this problem: > > http://codeforces.com/problemset/problem/71/A That's not a problem, it's a url. > The input and output is as wanted, but my answer keep rejected, here is > my source code http://txt.do/1smv That's not source code, it's a url. > Please, I need help. As my newsreader isn't a web browser, I can't help. Sorry. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web