Skip to main content
 首页 » 编程设计

python之不明白为什么我得到一个 'int' object is not iterable Error

2025年05月04日19zhoujg

<分区>

不明白为什么我会收到 TypeError: 'int' object is not iterable

first_age = int(input("Enter your age: ")) 
second_age = int(input("Enter your age: ")) 
total = sum(first_age, second_age) 
print("Together you're {} years old".format(total)) 
Enter your age: 1 
Enter your age: 1 
--------------------------------------------------------------------------- 
TypeError                                 Traceback (most recent call last) 
<ipython-input-25-6375ca82c6eb> in <module> 
      4 second_age = int(input("Enter your age: ")) 
      5  
----> 6 total = sum(first_age, second_age) 
      7  
      8 print("Together you're {} years old".format(total)) 
 
TypeError: 'int' object is not iterable 
 
TypeError                                 Traceback (most recent call last) 
<ipython-input-25-6375ca82c6eb> in <module> 
      4 second_age = int(input("Enter your age: ")) 
      5  
----> 6 total = sum(first_age, second_age) 
      7  
      8 print("Together you're {} years old".format(total)) 
 
TypeError: 'int' object is not iterable