for loop in python

Peter Otten __peter__ at web.de
Thu Apr 28 05:54:19 EDT 2016


g.v.aarthi at skct.edu.in wrote:

> start_list = [5, 3, 1, 2, 4]
> square_list = []
> 
> # Your code here!
> for square_list in start_list:

You are iterating over start_list, that's OK. But you are assigning the 
current value to square_list, a variable name that you already use for the 
list where you put result of your calculations. Pick another name.

>    x = pow(start_list, 2)

Look at the line above once more: did you really want the square of the 
complete start_list or only one item?

>    square_list.append(x)
>    square_list.sort()
> print square_list
> 
> TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
> Please provide me the solution for the above problem





More information about the Python-list mailing list