I am looking to create a program in python that asks the user to enter a list of numbers in [] format.
It then must count and display how many of those numbers in the list are between 1 and 10, 10 and 20,
20 and 30.
Each section of 10 are to be counted whether or not there is a number within that section meaning it can return a 0.
Here is what I have so far.
the_input = raw_input("Enter numbers... ")
the_list = [int(x) for x in the_input.strip("[]").split(",")]
group_counter = {}
for number in the_list:
group_start = (number // 10) * 10
group_end = group_start + 9
group_name = "%s-%s" % (group_start, group_end)
group_counter.setdefault(group_name, 0)
group_counter[group_name] += 1
for name, count in group_counter.items():
print "There were %s in %s" % (count, name)
collections.Counteris your friend here.Edit: If you want the printed counts to only show for 0-9 to 90-99, then just change the bin_range line to
bin_range = range(10)