Python 3.30 TypeError: object of type int has no len() [closed]

2024/11/16 13:57:19

Here's the error I get for i in range(len(n)):

TypeError: object of type 'int' has no len()

I have seen other posts on here but haven't found the solution yet.
I'm confused. Please comment if you know what's going on here.

Here's my code:

#ch6.ex11.pydef squareEach(x):sqrt = x*xreturn sqrtdef main():n = []n = eval(input("Enter a list of numbers to be squared seperated by comma:\n"))i = 1sqrtn = ()for i in range(len(n)):sqrtn = squareEach(n)++iprint("Here's your results: ",sqrtn)main()
Answer

n is an integer. You want

for i in range(n):
https://en.xdnf.cn/q/120324.html

Related Q&A

Is it possible to disable negative indexing? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

Google Colab Notebook completely freezes when training a YOLO model

I am following a tutorial to train custom object detection model using YOLO. This is the tutorial and also where I got the Notebook Everything works fine until the training bit which is the last cell. …

Generate 4 columns of data such that each row sum to 100

How do I write a python program that can randomly generate 4 columns of data such that the sum of the numbers of each row is 100?

Nan to Num Python

I have multiple array that for those I calculate a linear regression, but sometimes it gives me 0/0 values which gives me a NaN. I know that to convert an array where there are numbers that are NaN you…

Class constructor able to init with an instance of the same class object

Can python create a class that can be initialised with an instance of the same class object?Ive tried this:class Class(): def __init__(self,**kwargs):print selfself = kwargs.get(obj,self)print selfif …

Python Logical Operators

I am currently learning Python3, but I dont understand Logical Operators. Here is the link: http://pymbook.readthedocs.org/en/py3/operatorsexpressions.html#logical-operators First of all, it seems that…

Partial Pivoting In Pandas SQL Or Spark

Partial Pivoting In Pandas SQL Or Spark Make the Year remain as Rows, and have the States Transpose to columns Take Pecentage value of a Gender Male Race White, InputOutput

Python to create a find-replace dictionary from a word vba macro

I have a very big macro Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWith Selection.Find.Text = "asa".Replacement.Text = "fsa".Forward = True.Wrap = wdFin…

Converting many .txt files into csv and combining them

I have many .txt files. I want to convert a few files ending with specific names into csv and combine them into one csv. ### Folder Name: text_files python_gramm.py aadd01.txt aaxx02.txt aaff03.txt hhd…

Calculation between two columns in Python?

When I tried to do some calculation between two columns (like division), I get an error: column_ratio[x]=(float(column1[y]))/(float(column2[z])) TypeError: tuple indices must be integers, not str. C…