[pythonvis] Re: Short projet

  • From: Dzhovani <dzhovani.chemishanov@xxxxxxxxx>
  • To: pythonvis@xxxxxxxxxxxxx
  • Date: Wed, 03 Jun 2015 10:27:24 +0300

Hi Joseph,
Here is the task:
Write a function that takes a list, of indefinite size.
# The function needs a list to work
The list elements consist of numbers, in the range of 1 to 100, but
you have no idea how many list
elements there will be. Typical list But, as a sample, lengths might be
50 elements at most.
# I don't expect any particular length from the list, but the function
definitely expects numbers in the range 1:100
Process the list, and print the output in a series of lines that do not
exceed 32 characters each.
# A bit clumsily, but the 32 character requirement is met
Numbers on each line should be separated by a single space, and a number
should not span multiple lines.
# the "," in 'print each,' line does the job
Because the numbers are in the range of 1 through 100, some numbers take
fewer spaces than others, That is, the number 1 should be written as
“1” not “001”
, nor be space padded, such as “ 1”. Think of packing numbers together
in the interests of conserving braille display real estate.
# the if...elif...else statement in the inner loop covers that

Possible problems are the backSpace printed in the end and the fact
that maybe the function don't have to print the result, but to return 2d
array. Both problems are easy to solve with miner changes in the script.
Regarding your followup, I agree. The code can be refined some more.

On 3.6.2015 г. 08:53 ч., Joseph Lee wrote:


Hi,

Very impressive.

One important thing: Sometimes, when we solve something, we solve
something else. In your words, would you say the attached script
solves the original question posed by Jim? In other words, I’d like to
kindly say that it is not just the scripts that completes the puzzle –
it is user acceptance that matters more. I’d like to hear your opinion
first before saying mine so you can have a chance to say why your
solution works.

For Jim: Would you say the attached solution solves your original
question?

Cheers,

Joseph



*From:*pythonvis-bounce@xxxxxxxxxxxxx
[mailto:pythonvis-bounce@xxxxxxxxxxxxx] *On Behalf Of *Dzhovani
*Sent:* Tuesday, June 2, 2015 10:35 PM
*To:* pythonvis@xxxxxxxxxxxxx
*Subject:* [pythonvis] Re: Short projet



Hi,
I'm not sure that it is the best solution, so any critisism will be
highly appreciated. The code is attached, but I'm pasting it below as
well:

def presentNums(seq):
seq.reverse() # reverse the list for faster pop operation later

while len(seq) > 0:
line = [] # creates the line to be printed and sets it to be
empty at the beginning of the iterate
length = 0 # the supposed length of the printed line
prolong =0 # prolong will be a variable to hold how longer the
line will become. it adds one for the space in between
while len(seq) > 0:
if seq[-1] < 10:
prolong = 2
elif seq[-1] < 100:
prolong = 3
else:
prolong = 4
length += prolong
if length <= 33:
line.append(seq.pop())
else:
break # leaves the inner loop
for each in line:
print each,
print "\b" # after the line is printed, it removes the last
space from the line

seq = [1, 2, 3, 4, 56, 76, 100, 99, 56, 29, 82,93, 74, 48, 95, 43, 25,
36, 71, 100, 100, 100, 100, 13, 100,37, 86, 100, 100]
print "start function"
presentNums(seq)

On 2.6.2015 г. 17:33 ч., derek riemer wrote:

Oddly enough, I needed a variant this function that splits a 1
dimentional string into a 2 dimentional array of row length 10
yesterday and wrote it. but I will hold off posting it in case
anyone wishes to write it.

On 5/31/2015 7:58 PM, Jim Snowbarger wrote:

Anybody want to take a crack at this one?



Write a function that takes a list, of indefinite size. The
list elements consist of numbers, in the range of 1 to 100,
but you have no idea how many list elements there will be.
Typical list But, as a sample, lengths might be 50 elements at
most.

Process the list, and print the output in a series of lines
that do not exceed 32 characters each.



Numbers on each line should be separated by a single space,
and a number should not span multiple lines.

Because the numbers are in the range of 1 through 100, some
numbers take fewer spaces than others, That is, the number 1
should be written as “1” not “001” , nor be space padded, such
as “ 1”. Think of packing numbers together in the interests
of conserving braille display real estate.



If anybody takes it on, let me know.















------------------------------------------------------------------------

<http://www.avast.com/>



В писмото няма вируси или малуер, защото avast! Антивирус
<http://www.avast.com/> защитата е активна.






---
В писмото няма вируси или малуер, защото avast! Антивирус защитата е активна.
http://www.avast.com

Other related posts: