Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Travis Wion
Travis Wion
530 Points

how can i get the count function to distinguish the differences between the numbers 1 and 10

one = input("What is your number: ") print(one.count("1" ,0, 100)) print(one.count("2",0 , 100)) print(one.count("3",0 , 100))

1 Answer

Steven Parker
Steven Parker
216,083 Points

I'm assuming you're inputting a list of numbers (or why else use "count"?) and separating them with whitespace.

The issue here is that you are using the string version of "count", which is only looking at the individual digits. To distinguish multi-digit numbers, you could convert the input into a list, and use the list version of "count". Here's an example:

nums = input("What are your numbers: ").split()
print("ones:  ", nums.count("1"))
print("twos:  ", nums.count("2"))
print("threes:", nums.count("3"))

A bit more sophisticated approach would be to convert the strings into integers, and then do numeric comparisons:

nums = [ int(n) for n in input("What are your numbers: ").split() ]
print("ones:  ", nums.count(1))
print("twos:  ", nums.count(2))
print("threes:", nums.count(3))