Hello brothers got a python question for you all solve this python
code and comment the answer
a = []
for i in range(10):
a.append(i * ++i)
for a[i] in a:
print(a[i])
what will be the output of this code ?
Hello brothers got a python question for you all solve this python
code and comment the answer
a = []
for i in range(10):
a.append(i * ++i)
for a[i] in a:
print(a[i])
what will be the output of this code ?
For further actions, you may consider blocking this person and/or reporting abuse
Said MOUNAIM -
Alexis Clarembeau -
Kuhanraja A R -
Hamza Khan -
Top comments (11)
Aside from what the others have said, there is also no ++ operator in python.
The line
for a[i] in a
will work, but it has no point and looks awful and confusing.You should add a note to point out that this code is a parody or something.
A nice change to the code would've been to write
a = a.append(i)
. I found that many beginners confuse the return type of the append method.undefined capital I in a[I]
Sorry for that i accidently putted that here i edited it now
Then after fixing all errors.
Output is
0
1
4
9
16
25
36
49
64
64
CORRECT 👍🏻
Syntax error, indention expected on line 3?
I'm not sure but ++i will raise error because its not allowed in python.
Correct me if I'm wrong.
try running it bro
Three errors:
L3 Indentation expected
L3 SyntaxError: there's no ++ operator in Python
L5 Undefined symbol
l
well it has only one error in the end where the i is in caps but try running that code with
small i
0
1
4
9
16
25
36
49
64
64