사용자 입력을받는 프로그램을 만들려고 시도했습니다.이 프로그램은 숫자 문자열로 각 숫자가 몇 번이나 출력되는지 출력합니다. 그러나 int 객체가 반복 가능하지 않다는 것을 나타내는 TypeError를 수신합니까? 이 문제를 어떻게 해결할 것이며 왜 그런 일이 발생합니까? 고맙습니다.int 객체가 반복 가능하지 않습니까?
def main():
count = {}
user_input = input("Enter numbers separated by spaces: ")
for number in user_input.split():
if number in count:
count[number] = count[number] + 1
else:
count[number] = 1
print(count)
for k,v in count.values():
if v == 1:
print(k,"occurs one time")
else:
print(k,"occurs",v,"times")
main()
좋아. 고맙습니다. – user3495234