+ 1

x=[] for y in range(5): if y[b] % [/b]2==0: x.append(y) continue print (x)

How does if statement work and what is output

15th Apr 2023, 8:06 AM
Somvir Dhaka
Somvir Dhaka - avatar
4 Réponses
+ 8
[b] and [/b] are formatting annotations (bbcode), which should NOT be part of your actual code. It is markup for bold text. If you remove them, the code will work.
15th Apr 2023, 9:54 AM
Tibor Santa
Tibor Santa - avatar
+ 10
Please DO NOT put code in the title section. You can find out WHAT the output is by actually running the code.
15th Apr 2023, 8:24 AM
Lisa
Lisa - avatar
+ 9
Somvir Dhaka , the code you presented is very buggy. > in line 2, numbers are created by using a range(). > in line 3 the code uses indexes to access the numbers (coming from the range) like *y[b]*, but this fails since numbers are not subscriptable. also the indexes itself are creating errors, because *b* is never defined, also */b* does not work. > also the *continue statement* in line 5 has no effect. > so the complete line 3 is a total mess. may be you correct the code so that we can help you ? what is this code going to achieve?
15th Apr 2023, 9:50 AM
Lothar
Lothar - avatar
+ 6
It says syntax error. It points to line 3. And you have already finished 4 python courses. This should be easy for you.
15th Apr 2023, 9:34 AM
Paul
Paul - avatar