2012-09-01 3 views
0

이 정수가 순서를 유지하면서 행에 표시되도록하는 방법을 찾으려합니다.정수를 파이썬에서 행 형식으로 표시하십시오.

그러나 코드를 실행하면 여기에 표시됩니다.

Enter numbers 1... 22,34,35,40,55 
Enter numbers 2... 12,14,34,47,49 
Enter numbers 3... 1,4,10,19,30 

Section 1    # 
The number seqeuce is 0 between 0 and 9 
The number seqeuce is 0 between 10 and 19 
The number seqeuce is 1 between 20 and 29 
The number seqeuce is 2 between 30 and 39 
The number seqeuce is 1 between 40 and 49 
The number seqeuce is 1 between 50 and 59 
Section 2 
The number seqeuce is 0 between 0 and 9 
The number seqeuce is 2 between 10 and 19 
The number seqeuce is 0 between 20 and 29 
The number seqeuce is 1 between 30 and 39 
The number seqeuce is 2 between 40 and 49 
The number seqeuce is 0 between 50 and 59 
Section 3 
The number seqeuce is 2 between 0 and 9 
The number seqeuce is 2 between 10 and 19 
The number seqeuce is 0 between 20 and 29 
The number seqeuce is 1 between 30 and 39 
The number seqeuce is 0 between 40 and 49 
The number seqeuce is 0 between 50 and 59 
         # 

이 나는 ​​범위의 정수로 corresponing 위해 에서보고 싶은 것입니다.

Enter numbers 1... 22,34,35,40,55 
Enter numbers 2... 12,14,34,47,49 
Enter numbers 3... 1,4,10,19,30 
Section 1 
The number seqeuce is 0 0 1 2 1 1 # 
Section 2       # 
The number seqeuce is 0 2 0 1 2 0 # <-- Here is the sequennce from above 
Section 3       # 
The number seqeuce is 2 2 0 1 0 0 # 

내가 지금까지 무엇을 가지고 있는지.

import collections 

the_inputs = [] 

for i in range(3): 
    the_inputs.append(raw_input("Enter numbers {}... ".format(i+1))) 

the_lists = [] 

for the_input in the_inputs: 
    the_lists.append([int(x)//10 for x in the_input.strip("[]").split(",")]) 

for i, the_list in enumerate(the_lists): 
    print "Section {}".format(i+1) 
    group_counter = collections.Counter(the_list) 
    bin_range = range (6) 
    for bin_tens in bin_range: 
     print "The number seqeuce is {} between {} and {}".format(group_counter[bin_tens], bin_tens*10, bin_tens*10+9) 

답변

1

간단한 재배치 :

print "The number sequence is", 
for bin_tens in bin_range: 
    print group_counter[bin_tens], 
print 
+0

이것은 colunm 형식으로 출력합니다 나는 그것을 개별적으로 각각의 정수를 나누는 것 같아요. – Howie

+0

@Howie'print'의 끝에','을주의하십시오. 'print'가 개행을 추가하는 것을 막습니다. – halex

+0

이것은 이미 사용중인 동일한 코드입니다. 이것이 어떻게 더 좋게 만들 것인지, 내가 무엇을 요구하는지 알게 될 것입니다. – Howie

관련 문제