Others have answered the question, directly. Perhaps the real issue is how to solve a problem that [quote=âMoon Light, post:1, topic:41545, username:Moonlight001â]i don't understand
[/quote]? ie where the computer is doing something differently - and need to work-out, what is it doing?
Taking the non-question first: [:=âMoon Light, post:1, topic:41545, username:Moonlight001â]# i understand this will result to [0,1,2,3,4]
[/quote], the understanding can be proven by adding a âdebug-print statementâ:
print( my_list )
There is now âproofâ that computer has behaved as-expected - more importantly, both thinking on the same lines. Others have shown how to re-wire a list-comprehension into its long-form equivalent, so going completely over-board:
m = list()
for i in range( 4, 0, -1, ):
print( i, end=", ", )
if my_list[ i ] % 2 != 0:
print( "even" )
m.append( i )
else:
print( "odd" )
by adding the debug-print statements there is a blow-by-blow illustration of what the computer is doing with the code.
Assumptions: that you have learned about list-comprehensions, and the effect of the modulo-operator, before attempting the exam.
Speaking personally: no longer use debug-prints because have to remember to put them in first, and take them out, last!
The Python tool for the job is called a âDebuggerâ. Such are built-in to competent developer tools, such as PyCharm. However, thatâs a whole extra skill to learn, so Phil Guoâs excellent Python Tutor is recommended for developing and investigating snippets (like this one) and providing the desired visual insight. The Thonny IDE for beginners provides something similar.