[pythonvis] Re: Short projet

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

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.















---
В писмото няма вируси или малуер, защото avast! Антивирус защитата е активна.
http://www.avast.com
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 previous 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)

Other related posts: