我现在只想输入要单独计算的多组整数。它会像这样流动。
首先一次获取用户输入。
输入数字 1... 2,4,23,45,57
输入数字 2... 9,23,45,47,33
输入数字 3... 2,41,23,45,55
然后一次性打印出来。
数字 1... 2,0,1,0,1,1 的序列
数字 2... 1,0,1,1,2,0 的序列
数字 3 的序列... 1,0,1,0,2,1
这是我的代码。
import collections
the_input1 = raw_input("Enter numbers 1... ")
the_input2 = raw_input("Enter numbers 2... ")
the_input3 = raw_input("Enter numbers 3... ")
the_list1 = [int(x) for x in the_input1.strip("[]").split(",")]
the_list2 = [int(x) for x in the_input2.strip("[]").split(",")]
the_list3 = [int(x) for x in the_input3.strip("[]").split(",")]
group_counter = collections.Counter(x//10 for x in the_list1)
group_counter = collections.Counter(x//10 for x in the_list2)
group_counter = collections.Counter(x//10 for x in the_list3)
bin_range = range (6)
for bin_tens in bin_range:
print "There were {} in {} to {}".format(group_counter[bin_tens], bin_tens*10, bin_tens*10+9)
任何回应将不胜感激..谢谢..