+ 1

Python3 for loop nested

for q in range(10): q ** 2 print(q) for l in q: p = l ** 2 print(p) I’m having trouble to fix this code in order to have every number in the range powered two times. I know there are other different methods to accomplish this task, but i want to do it in this way, if is possible. Pycharm is rising this error: TypeError: 'int' object is not iterable Please help me!

22nd Jan 2018, 6:31 AM
Michael Nervo
Michael Nervo - avatar
4 Respostas
0
for i in range(9): for j in range(2): i=i**2 print(str(i)) Anyway I found it
25th Jan 2018, 11:05 AM
Michael Nervo
Michael Nervo - avatar
+ 10
This is what *I suppose* you want. for q in range(10): q = q ** 2 print(str(q) + ':', end='') for l in range(q): p = l ** 2 print(str(p)+' ', end='') print('')
22nd Jan 2018, 6:32 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
I i basically want this output: 0 1 16 81 256 625 1296 2401 4096 6561 I want to power the power ((3**2)**2)
22nd Jan 2018, 7:07 AM
Michael Nervo
Michael Nervo - avatar
0
for q in range(10): print(q**4)
22nd Jan 2018, 11:56 AM
richard