我得到了一个号码:
示例:12345
我应该把这个数字的每一个数字分开,并附加到一个列表(整数列表)中。
num = list(int(input('Enter the number\n')))
print(num)
获取错误:
Exception has occurred: TypeError 'int' object is not iterable
所需输出:[1, 2, 3, 4, 5]
n,m,k=map(int, input().split())
data=list(map(int, input().split()))
for i in data:
print(i)
#consequence=2 3 4 5 6
for i in data:
print(max(i))
#consequence= TypeError:'int‘对象不可迭代
如果int是可迭代的,那么为什么我可以在for循环中使用int?为什么在这种情况下我不能使用max()函数?
简单的问题。
我有一个数字(整数):
mynumber = 1239
我想把它转换成一个单独的整数列表,比如[1,2,3,9]
numbersplit = [int(x) for x in mynumber]
但是我得到了一个错误:
TypeError: 'int' object is not iterable
为什么这个不起作用?我只是确保ints是真正的ints。
但是,当我将它包装在str中时,它可以正常工作吗?
[int(x) for x in str(mynumber)]
[1, 2, 3, 9, 8, 9, 8, 7, 2, 3, 9, 4, 7, 8]
是否需
我正在从一个包含MLB播放器统计数据的输入文件中读取数据。文件的每一行包含与每个播放器相关的9个元素。我正在计算一些统计数据,并将它们添加到使用player统计数据创建的列表的末尾,但是正在得到一个类型错误,指定了float object is not iterable。下面是用于从输入文件填充列表的代码:
def readInput(fileName):
stats = []
try:
fh = open(fileName, "r")
#populated the stats list
for line in f
wcyear = 2000
def worldcup():
global wcyear
for i in wcyear:
wcyear = wcyear+4
print wcyear
print 'world cup year: ',wcyear
worldcup()
print 'Out of function wc year: ',wcyear
我得到的错误是:TypeError: 'int' object is not iterable是全局变量,循环中不支持吗?
我一直试图显示来自JSON文件的评论列表。我一直在犯这个错误:
回溯(最近一次调用):文件"JsonExtraction.py",第7行,在len(Data)中进行注释: TypeError:'int‘对象不可迭代
我的代码如下所示:
import json
data = []
for line in open('rating_company_small.json', 'r'):
data.append(json.loads(line))
for comment in len(data):
print(comment
我写了一些代码:
def ICP(x):
numofrepeat=0
warning=0
while numofrepeat<len(str(x)) or (x[numofrepeat]==2) or (x[numofrepeat]==3) or (x[numofrepeat]==5) or (x[numofrepeat]==7):
if (x[numofrepeat]==0):
warning=warning+1
if warning>1:
numofrepeat=len(x)
我知道...在JavaScript中的传播操作符。我们可以在数组和对象上使用它:
let user = {
name: "aman",
rollno: 11
}
let newobj1 = {...user}
let newobj2 = [...user]
console.log(newobj1)
console.log(newobj2)
为什么newobj2会给出一个错误,TypeError: user is not iterable,但是newobj1工作得很好?
我是蟒蛇的初学者,学习一本书来练习。在我的书中,作者使用了以下代码
s, k = 0
但我知道错误是:
Traceback (most recent call last): File "<stdin>", line 1, in
<module> TypeError: 'int' object is not iterable
我想知道这里发生了什么。
因此,我在python中编写了这个简单的程序,它的函数名为num,函数以两个参数作为整数,并检查其中是否存在"20“,如果是,则返回True,否则返回False,您会注意到,在if语句中,我调用了另一个函数sum,它是python中内置的函数,所以当我试图传递函数中的a和b的值而不将它们作为元组传递时,它会给出下面提到的错误。所以我的问题是,当我像这个sum((a,b))而不是这个sum(a,b)传递它们时,它为什么会工作呢?
File "c.py", line 8, in <module>
print(num(220,10))
File
我试着解决Python的10.3练习
编写一个函数,该函数接受一个数字列表并返回累积和;也就是说,一个新的列表,其中ith元素是原始列表中第一个i + 1元素的和。例如,[1, 2, 3]的累积和是[1, 3, 6]。
我得到了一个包含以下代码的TypeError:
def culm_sum(num):
res= []
a = 0
for i in num:
a += i
res += a
return res
当我给culm_sum([1, 2, 3])打电话的时候
TypeError: 'int' ob
我不明白为什么我要得到一个TypeError:'int‘对象是不可迭代的
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
---------------------
我试图在队列类中创建一个程序,下面是我的代码:
def count(self): #im having a problem with this def count
vowels=0
for i in self:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i
实际上,这里有三个例子。
>>> result = []
>>> for k in range(10):
>>> result += k*k
>>> result = []
>>> for k in range(10):
>>> result.append(k*k)
>>> result = [k*k for k in range(10)]
第一个会出错。错误打印如下
TypeError: 'int' object is not iter
我试图在列表中找到一个整数,这个整数会出现奇数。下面是我正在尝试实现的解决方案,但我得到了以下内容: TypeError:类型为'int‘的参数不可迭代
我不明白为什么我的清单理解没有返回任何东西。如果我理解了错误,有一个迭代在某个地方进行,而我没有看到?
from collections import Counter
def find_it(seq):
new_seq = Counter()
odd_appearances = None
for i in seq:
new_seq[i] += 1
for v in new_seq.va
我在python中试验tuple时,偶然发现了这个问题。 t=tuple("2",) # works 但是 t=tuple(1,) # fails with error TypeError: 'int' object is not iterable 鉴于 t=(1,) # works 有人能解释一下为什么会这样吗?
我能做到
>>> s = {1}
>>> type(s)
<class 'set'>
但
>>> s = set(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
有什么关系?
我正在做Monty Hall模拟,当我运行这些代码行时,我得到错误消息"int object is not iterable",但我已经在使用range函数了。后来,我在一个更简单的代码上尝试了它,它基本上做了同样的事情,并且运行得很顺利。
def run_game(n):
loss, win=0
for i in range(1,n):
switch(True)
if nagrada==odabir_vrata:
win+=1
else:
loss+=1
v
我是Python的新手。下面是我用来打印x^3的一段简单代码
def f(n):
for x in range(n):
yield x**3
for x in f(5):
print x
它打印出正确的答案。
def f(n):
return [x**3 for x in range(n)]
for x in f(5):
print x
它还会打印正确的答案
def f(n):
for x in range(n):
return x**3
for x in f(5):
print x
我得到了一个
TypeErro
sum = []
def s(d):
d = list[int]
sum = []
for i in d:
sum += i
return(sum)
s([1, 2, 3])
Python给了我以下消息:TypeError: 'type' object is not iterable.
我如何使代码工作?
我有意识地试图犯一个错误,使用“except”语句,这样我就可以干扰预期的错误。
a = 1
for i in a:
try:
print(a*a)
except TypeError:
print("Hata")
我想用'for‘循环运行一个整数并干扰'TypeError’,但不知何故,我不能触发'try‘语句,也不能触发’except‘语句。因为我不明白原因,所以我需要一些帮助。提前感谢您的帮助。
我意外地看到,这会导致V8 (Chrome、Node.js等)出现错误:
for (let val of Symbol()) { /*...*/ }
TypeError:符号不是一个函数,或者它的返回值不可迭代
似乎任何其他不可迭代的值(包括一个函数)都会导致另一个错误:
for (let val of function () { throw 'never called' }) { /*...*/ }
TypeError:(中间值)不可迭代
正如所述,错误是特定于Chrome的:
TypeError:'x‘不是一个函数,或者它的返回值不可迭代(Chro
AgeList = [0]
for i in range (5):
age = int(input("Enter Age: "))
if (age>=18):
print("You're eligible to vote.")
else:
print(f"Wait {18-age} years to vote")
AgeList = AgeList.extend(age)
print(AgeList) 抛出这个。我不知道该怎么解决这个问题。尝试执行AgeList +
from random import randint
number_of_trials = 100
range_of_random_numbers = 1000
for each in number_of_trials:
print randint(range(range_of_random_numbers))
我是蟒蛇的初学者。当我尝试运行上述代码时,会得到以下错误:
TypeError:'int‘对象不可迭代
我试图从一个范围(在range_of_numbers中定义)获取一个随机数,以打印一定数量的时间(在number_of_trials中定义)。帮帮忙,我做错什
我写了这段简短的代码:
from cv2 import cv2
img = cv2.imread("1.png")
print("Высота:"+str(img.shape[0]))
print("Ширина:" + str(img.shape[1]))
print("Количество каналов:" + str(img.shape[2]))
for x in img.shape[0]:
for y in img.shape[1]:
if img[x, y] == (255, 255, 2
我正面对3000多个目录和子目录中的docx。我必须准备一个由文件名组成的列表,并从docx中的表中提取信息。我已经成功地将所有docx添加到列表targets_in_dir中,将其与非相关文件分开。
问题:我想遍历targets_in_dir,从docx中提取所有表,
len_target =len(targets_in_dir)
file_processed=[]
string_tables=[]
for i in len_target:
doc = docx.Document(targets_in_dir[i])
file_processed.append(targe
给出如下结构的一类:
public class Section extends IterableWidgetTemplate<Item>{
private List<WebElement> items1;
// other non iterable methods
private int indexOf(final Item item) {
int i = Iterables.indexOf(this, new Predicate<Item>() {
. . .
}